{"id":1174781,"date":"2025-01-15T17:23:02","date_gmt":"2025-01-15T09:23:02","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1174781.html"},"modified":"2025-01-15T17:23:05","modified_gmt":"2025-01-15T09:23:05","slug":"python%e7%9f%a9%e9%98%b5%e5%be%88%e5%a4%a7%e5%a6%82%e4%bd%95%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1174781.html","title":{"rendered":"python\u77e9\u9635\u5f88\u5927\u5982\u4f55\u5904\u7406"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25110404\/6f637090-fc29-4869-a1a9-6c9e15f7c194.webp\" alt=\"python\u77e9\u9635\u5f88\u5927\u5982\u4f55\u5904\u7406\" \/><\/p>\n<p><p> <strong>Python\u5904\u7406\u5927\u578b\u77e9\u9635\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5206\u5e03\u5f0f\u8ba1\u7b97\u3001\u5185\u5b58\u6620\u5c04\u3001\u7a00\u758f\u77e9\u9635\u3001\u5206\u5757\u5904\u7406\u7b49\u65b9\u6cd5\u3002<\/strong>\u4f8b\u5982\uff0c\u5185\u5b58\u6620\u5c04\u6280\u672f\u53ef\u4ee5\u5c06\u5927\u578b\u77e9\u9635\u5b58\u50a8\u5728\u78c1\u76d8\u4e0a\uff0c\u800c\u4e0d\u662f\u5b8c\u5168\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u4ece\u800c\u8282\u7701\u5185\u5b58\u7a7a\u95f4\u5e76\u63d0\u9ad8\u5904\u7406\u6548\u7387\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u7684\u4e00\u79cd\u65b9\u6cd5\u2014\u2014\u5185\u5b58\u6620\u5c04\u6280\u672f\u3002<\/p>\n<\/p>\n<p><p>\u5185\u5b58\u6620\u5c04\uff08Memory Mapping\uff09\u662f\u4e00\u79cd\u6280\u672f\uff0c\u901a\u8fc7\u5c06\u6587\u4ef6\u6620\u5c04\u5230\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\uff0c\u4f7f\u5f97\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u53ef\u4ee5\u50cf\u8bbf\u95ee\u5185\u5b58\u4e2d\u7684\u6570\u636e\u4e00\u6837\u88ab\u8bbf\u95ee\u3002Python\u4e2d\u7684<code>numpy<\/code>\u5e93\u63d0\u4f9b\u4e86<code>memmap<\/code>\u7c7b\u6765\u5b9e\u73b0\u8fd9\u79cd\u6280\u672f\u3002\u4f7f\u7528<code>numpy.memmap<\/code>\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u4e00\u4e2a\u5927\u578b\u77e9\u9635\u5b58\u50a8\u5728\u78c1\u76d8\u4e0a\uff0c\u5e76\u901a\u8fc7\u64cd\u4f5c\u5185\u5b58\u6620\u5c04\u5bf9\u8c61\u6765\u8bbf\u95ee\u548c\u4fee\u6539\u77e9\u9635\u4e2d\u7684\u6570\u636e\uff0c\u800c\u4e0d\u9700\u8981\u5c06\u6574\u4e2a\u77e9\u9635\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002\u8fd9\u5bf9\u4e8e\u5904\u7406\u8d85\u51fa\u5185\u5b58\u5bb9\u91cf\u7684\u5927\u578b\u77e9\u9635\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5185\u5b58\u6620\u5c04\u6587\u4ef6<\/strong><\/h2>\n<p>filename = &#39;large_matrix.dat&#39;<\/p>\n<p>shape = (10000, 10000)<\/p>\n<p>dtype = &#39;float32&#39;<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5185\u5b58\u6620\u5c04\u5bf9\u8c61<\/strong><\/h2>\n<p>matrix = np.memmap(filename, dtype=dtype, mode=&#39;w+&#39;, shape=shape)<\/p>\n<h2><strong>\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e<\/strong><\/h2>\n<p>matrix[0, 0] = 1.0<\/p>\n<p>matrix[9999, 9999] = 2.0<\/p>\n<h2><strong>\u4fdd\u5b58\u4fee\u6539\u5e76\u5173\u95ed\u5185\u5b58\u6620\u5c04\u6587\u4ef6<\/strong><\/h2>\n<p>matrix.flush()<\/p>\n<p>del matrix<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u5904\u7406\u5927\u578b\u77e9\u9635\u65f6\u8282\u7701\u5185\u5b58\u7a7a\u95f4\uff0c\u5e76\u4e14\u4f9d\u7136\u80fd\u591f\u9ad8\u6548\u5730\u8fdb\u884c\u6570\u636e\u64cd\u4f5c\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5176\u4ed6\u5904\u7406\u5927\u578b\u77e9\u9635\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<h2><strong>\u4e00\u3001\u5206\u5e03\u5f0f\u8ba1\u7b97<\/strong><\/h2>\n<p><p>\u5206\u5e03\u5f0f\u8ba1\u7b97\u662f\u4e00\u79cd\u901a\u8fc7\u5c06\u4efb\u52a1\u5212\u5206\u4e3a\u591a\u4e2a\u5b50\u4efb\u52a1\uff0c\u5e76\u5c06\u8fd9\u4e9b\u5b50\u4efb\u52a1\u5206\u914d\u5230\u591a\u4e2a\u8ba1\u7b97\u8282\u70b9\u4e0a\u6267\u884c\uff0c\u4ece\u800c\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\u7684\u65b9\u6cd5\u3002\u5728\u5904\u7406\u5927\u578b\u77e9\u9635\u65f6\uff0c\u5206\u5e03\u5f0f\u8ba1\u7b97\u53ef\u4ee5\u6709\u6548\u5730\u5229\u7528\u591a\u53f0\u8ba1\u7b97\u673a\u7684\u8ba1\u7b97\u8d44\u6e90\uff0c\u51cf\u5c11\u8ba1\u7b97\u65f6\u95f4\u3002<\/p>\n<\/p>\n<p><h2>\u4f7f\u7528Dask\u5e93<\/h2>\n<\/p>\n<p><p>Dask\u662f\u4e00\u4e2a\u7528\u4e8e\u5e76\u884c\u8ba1\u7b97\u7684Python\u5e93\uff0c\u53ef\u4ee5\u5904\u7406\u6bd4\u5185\u5b58\u5927\u7684\u6570\u636e\u96c6\u3002Dask\u63d0\u4f9b\u4e86\u4e0e<code>numpy<\/code>\u517c\u5bb9\u7684\u63a5\u53e3\uff0c\u4f7f\u5f97\u5904\u7406\u5927\u578b\u77e9\u9635\u53d8\u5f97\u66f4\u52a0\u5bb9\u6613\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import dask.array as da<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aDask\u6570\u7ec4<\/strong><\/h2>\n<p>shape = (10000, 10000)<\/p>\n<p>chunks = (1000, 1000)<\/p>\n<p>matrix = da.random.random(shape, chunks=chunks)<\/p>\n<h2><strong>\u6267\u884c\u8ba1\u7b97<\/strong><\/h2>\n<p>result = matrix.mean().compute()<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4f7f\u7528Apache Spark<\/h2>\n<\/p>\n<p><p>Apache Spark\u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u8ba1\u7b97\u6846\u67b6\uff0c\u53ef\u4ee5\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u96c6\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528PySpark\uff08Spark\u7684Python\u63a5\u53e3\uff09\u6765\u5904\u7406\u5927\u578b\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from pyspark.sql import SparkSession<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efaSpark\u4f1a\u8bdd<\/strong><\/h2>\n<p>spark = SparkSession.builder.appName(&#39;LargeMatrix&#39;).getOrCreate()<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5927\u578b\u77e9\u9635<\/strong><\/h2>\n<p>shape = (10000, 10000)<\/p>\n<p>matrix = np.random.rand(*shape)<\/p>\n<h2><strong>\u5c06\u77e9\u9635\u8f6c\u6362\u4e3aDataFrame<\/strong><\/h2>\n<p>df = spark.createDataFrame(matrix.tolist())<\/p>\n<h2><strong>\u6267\u884c\u8ba1\u7b97<\/strong><\/h2>\n<p>result = df.groupBy().avg().collect()<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e8c\u3001\u5185\u5b58\u6620\u5c04<\/strong><\/h2>\n<p><p>\u5185\u5b58\u6620\u5c04\uff08Memory Mapping\uff09\u662f\u4e00\u79cd\u5c06\u6587\u4ef6\u6620\u5c04\u5230\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\u7684\u6280\u672f\uff0c\u53ef\u4ee5\u5c06\u5927\u578b\u77e9\u9635\u5b58\u50a8\u5728\u78c1\u76d8\u4e0a\uff0c\u5e76\u901a\u8fc7\u64cd\u4f5c\u5185\u5b58\u6620\u5c04\u5bf9\u8c61\u6765\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h2>\u4f7f\u7528numpy.memmap<\/h2>\n<\/p>\n<p><p><code>numpy<\/code>\u5e93\u63d0\u4f9b\u4e86<code>memmap<\/code>\u7c7b\u6765\u5b9e\u73b0\u5185\u5b58\u6620\u5c04\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>numpy.memmap<\/code>\u5c06\u4e00\u4e2a\u5927\u578b\u77e9\u9635\u5b58\u50a8\u5728\u78c1\u76d8\u4e0a\uff0c\u5e76\u901a\u8fc7\u64cd\u4f5c\u5185\u5b58\u6620\u5c04\u5bf9\u8c61\u6765\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5185\u5b58\u6620\u5c04\u6587\u4ef6<\/strong><\/h2>\n<p>filename = &#39;large_matrix.dat&#39;<\/p>\n<p>shape = (10000, 10000)<\/p>\n<p>dtype = &#39;float32&#39;<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5185\u5b58\u6620\u5c04\u5bf9\u8c61<\/strong><\/h2>\n<p>matrix = np.memmap(filename, dtype=dtype, mode=&#39;w+&#39;, shape=shape)<\/p>\n<h2><strong>\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e<\/strong><\/h2>\n<p>matrix[0, 0] = 1.0<\/p>\n<p>matrix[9999, 9999] = 2.0<\/p>\n<h2><strong>\u4fdd\u5b58\u4fee\u6539\u5e76\u5173\u95ed\u5185\u5b58\u6620\u5c04\u6587\u4ef6<\/strong><\/h2>\n<p>matrix.flush()<\/p>\n<p>del matrix<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4f7f\u7528h5py\u5e93<\/h2>\n<\/p>\n<p><p><code>h5py<\/code>\u662f\u4e00\u4e2a\u7528\u4e8e\u64cd\u4f5cHDF5\u6587\u4ef6\u7684Python\u5e93\uff0c\u53ef\u4ee5\u5c06\u5927\u578b\u77e9\u9635\u5b58\u50a8\u5728HDF5\u6587\u4ef6\u4e2d\uff0c\u5e76\u901a\u8fc7\u64cd\u4f5cHDF5\u6587\u4ef6\u5bf9\u8c61\u6765\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import h5py<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aHDF5\u6587\u4ef6<\/strong><\/h2>\n<p>filename = &#39;large_matrix.h5&#39;<\/p>\n<p>with h5py.File(filename, &#39;w&#39;) as f:<\/p>\n<p>    shape = (10000, 10000)<\/p>\n<p>    dtype = &#39;float32&#39;<\/p>\n<p>    # \u521b\u5efa\u4e00\u4e2a\u6570\u636e\u96c6<\/p>\n<p>    dataset = f.create_dataset(&#39;matrix&#39;, shape=shape, dtype=dtype)<\/p>\n<p>    # \u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e<\/p>\n<p>    dataset[0, 0] = 1.0<\/p>\n<p>    dataset[9999, 9999] = 2.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e09\u3001\u7a00\u758f\u77e9\u9635<\/strong><\/h2>\n<p><p>\u7a00\u758f\u77e9\u9635\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u77e9\u9635\uff0c\u5176\u4e2d\u5927\u591a\u6570\u5143\u7d20\u4e3a\u96f6\u3002\u5728\u5904\u7406\u5927\u578b\u7a00\u758f\u77e9\u9635\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u7a00\u758f\u77e9\u9635\u6570\u636e\u7ed3\u6784\u6765\u8282\u7701\u5185\u5b58\u7a7a\u95f4\uff0c\u5e76\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h2>\u4f7f\u7528scipy.sparse<\/h2>\n<\/p>\n<p><p><code>scipy.sparse<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u591a\u79cd\u7a00\u758f\u77e9\u9635\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u7528\u4e8e\u5b58\u50a8\u548c\u64cd\u4f5c\u7a00\u758f\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>from scipy.sparse import csr_matrix<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7a00\u758f\u77e9\u9635<\/strong><\/h2>\n<p>shape = (10000, 10000)<\/p>\n<p>matrix = np.random.rand(*shape)<\/p>\n<p>matrix[matrix &lt; 0.99] = 0<\/p>\n<p>sparse_matrix = csr_matrix(matrix)<\/p>\n<h2><strong>\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e<\/strong><\/h2>\n<p>print(sparse_matrix[0, 0])<\/p>\n<p>sparse_matrix[0, 0] = 1.0<\/p>\n<p>print(sparse_matrix[0, 0])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4f7f\u7528scikit-sparse<\/h2>\n<\/p>\n<p><p><code>scikit-sparse<\/code>\u662f\u4e00\u4e2a\u7528\u4e8e\u64cd\u4f5c\u7a00\u758f\u77e9\u9635\u7684Python\u5e93\uff0c\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u7a00\u758f\u77e9\u9635\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>from sksparse.cholmod import cholesky<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7a00\u758f\u77e9\u9635<\/strong><\/h2>\n<p>shape = (10000, 10000)<\/p>\n<p>matrix = np.random.rand(*shape)<\/p>\n<p>matrix[matrix &lt; 0.99] = 0<\/p>\n<p>sparse_matrix = csr_matrix(matrix)<\/p>\n<h2><strong>\u8fdb\u884cCholesky\u5206\u89e3<\/strong><\/h2>\n<p>factor = cholesky(sparse_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u56db\u3001\u5206\u5757\u5904\u7406<\/strong><\/h2>\n<p><p>\u5206\u5757\u5904\u7406\u662f\u4e00\u79cd\u5c06\u5927\u578b\u77e9\u9635\u5212\u5206\u4e3a\u591a\u4e2a\u5c0f\u5757\uff0c\u5e76\u9010\u5757\u8fdb\u884c\u5904\u7406\u7684\u65b9\u6cd5\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u51cf\u5c11\u5185\u5b58\u4f7f\u7528\uff0c\u5e76\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h2>\u4f7f\u7528numpy.array_split<\/h2>\n<\/p>\n<p><p><code>numpy<\/code>\u5e93\u63d0\u4f9b\u4e86<code>array_split<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u5c06\u4e00\u4e2a\u6570\u7ec4\u5212\u5206\u4e3a\u591a\u4e2a\u5c0f\u5757\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5927\u578b\u77e9\u9635<\/strong><\/h2>\n<p>shape = (10000, 10000)<\/p>\n<p>matrix = np.random.rand(*shape)<\/p>\n<h2><strong>\u5c06\u77e9\u9635\u5212\u5206\u4e3a\u591a\u4e2a\u5c0f\u5757<\/strong><\/h2>\n<p>blocks = np.array_split(matrix, 10)<\/p>\n<h2><strong>\u9010\u5757\u8fdb\u884c\u5904\u7406<\/strong><\/h2>\n<p>for block in blocks:<\/p>\n<p>    result = block.mean()<\/p>\n<p>    print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4f7f\u7528dask.array.map_blocks<\/h2>\n<\/p>\n<p><p>Dask\u63d0\u4f9b\u4e86<code>map_blocks<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u5c06\u4e00\u4e2aDask\u6570\u7ec4\u5212\u5206\u4e3a\u591a\u4e2a\u5c0f\u5757\uff0c\u5e76\u5bf9\u6bcf\u4e2a\u5c0f\u5757\u5e94\u7528\u4e00\u4e2a\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import dask.array as da<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aDask\u6570\u7ec4<\/strong><\/h2>\n<p>shape = (10000, 10000)<\/p>\n<p>chunks = (1000, 1000)<\/p>\n<p>matrix = da.random.random(shape, chunks=chunks)<\/p>\n<h2><strong>\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570<\/strong><\/h2>\n<p>def process_block(block):<\/p>\n<p>    return block.mean()<\/p>\n<h2><strong>\u9010\u5757\u8fdb\u884c\u5904\u7406<\/strong><\/h2>\n<p>result = matrix.map_blocks(process_block).compute()<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e94\u3001\u5e76\u884c\u8ba1\u7b97<\/strong><\/h2>\n<p><p>\u5e76\u884c\u8ba1\u7b97\u662f\u4e00\u79cd\u901a\u8fc7\u540c\u65f6\u6267\u884c\u591a\u4e2a\u4efb\u52a1\u6765\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\u7684\u65b9\u6cd5\u3002\u5728\u5904\u7406\u5927\u578b\u77e9\u9635\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u591a\u6838CPU\u548cGPU\u8fdb\u884c\u5e76\u884c\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><h2>\u4f7f\u7528multiprocessing\u5e93<\/h2>\n<\/p>\n<p><p><code>multiprocessing<\/code>\u662fPython\u7684\u6807\u51c6\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u5e76\u884c\u8ba1\u7b97\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>multiprocessing.Pool<\/code>\u6765\u521b\u5efa\u4e00\u4e2a\u8fdb\u7a0b\u6c60\uff0c\u5e76\u5c06\u4efb\u52a1\u5206\u914d\u5230\u591a\u4e2a\u8fdb\u7a0b\u4e2d\u6267\u884c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>from multiprocessing import Pool<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5927\u578b\u77e9\u9635<\/strong><\/h2>\n<p>shape = (10000, 10000)<\/p>\n<p>matrix = np.random.rand(*shape)<\/p>\n<h2><strong>\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570<\/strong><\/h2>\n<p>def process_block(block):<\/p>\n<p>    return block.mean()<\/p>\n<h2><strong>\u5c06\u77e9\u9635\u5212\u5206\u4e3a\u591a\u4e2a\u5c0f\u5757<\/strong><\/h2>\n<p>blocks = np.array_split(matrix, 10)<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u8fdb\u7a0b\u6c60<\/strong><\/h2>\n<p>with Pool(4) as pool:<\/p>\n<p>    results = pool.map(process_block, blocks)<\/p>\n<p>print(results)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4f7f\u7528numba\u5e93<\/h2>\n<\/p>\n<p><p><code>numba<\/code>\u662f\u4e00\u4e2a\u7528\u4e8e\u52a0\u901fPython\u4ee3\u7801\u7684\u5e93\uff0c\u53ef\u4ee5\u5c06Python\u4ee3\u7801\u7f16\u8bd1\u4e3a\u673a\u5668\u7801\uff0c\u4ece\u800c\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>numba.jit<\/code>\u88c5\u9970\u5668\u6765\u52a0\u901f\u5904\u7406\u5927\u578b\u77e9\u9635\u7684\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>from numba import jit<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5927\u578b\u77e9\u9635<\/strong><\/h2>\n<p>shape = (10000, 10000)<\/p>\n<p>matrix = np.random.rand(*shape)<\/p>\n<h2><strong>\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570<\/strong><\/h2>\n<p>@jit(nopython=True, parallel=True)<\/p>\n<p>def process_matrix(matrix):<\/p>\n<p>    result = np.zeros(matrix.shape[0])<\/p>\n<p>    for i in range(matrix.shape[0]):<\/p>\n<p>        result[i] = matrix[i].mean()<\/p>\n<p>    return result<\/p>\n<h2><strong>\u6267\u884c\u8ba1\u7b97<\/strong><\/h2>\n<p>result = process_matrix(matrix)<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4f7f\u7528cupy\u5e93<\/h2>\n<\/p>\n<p><p><code>cupy<\/code>\u662f\u4e00\u4e2a\u7528\u4e8eGPU\u8ba1\u7b97\u7684Python\u5e93\uff0c\u63d0\u4f9b\u4e86\u4e0e<code>numpy<\/code>\u517c\u5bb9\u7684\u63a5\u53e3\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>cupy<\/code>\u5728GPU\u4e0a\u5904\u7406\u5927\u578b\u77e9\u9635\uff0c\u4ece\u800c\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cupy as cp<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5927\u578b\u77e9\u9635<\/strong><\/h2>\n<p>shape = (10000, 10000)<\/p>\n<p>matrix = cp.random.rand(*shape)<\/p>\n<h2><strong>\u6267\u884c\u8ba1\u7b97<\/strong><\/h2>\n<p>result = cp.mean(matrix)<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u516d\u3001\u4f18\u5316\u7b97\u6cd5<\/strong><\/h2>\n<p><p>\u5728\u5904\u7406\u5927\u578b\u77e9\u9635\u65f6\uff0c\u9009\u62e9\u5408\u9002\u7684\u7b97\u6cd5\u548c\u6570\u636e\u7ed3\u6784\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u4f18\u5316\u7b97\u6cd5\u548c\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<\/p>\n<p><h2>\u4f7f\u7528\u77e9\u9635\u5206\u89e3<\/h2>\n<\/p>\n<p><p>\u77e9\u9635\u5206\u89e3\u662f\u4e00\u79cd\u5c06\u77e9\u9635\u5206\u89e3\u4e3a\u591a\u4e2a\u7b80\u5355\u77e9\u9635\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u7528\u4e8e\u964d\u7ef4\u548c\u538b\u7f29\u6570\u636e\u3002\u5e38\u7528\u7684\u77e9\u9635\u5206\u89e3\u65b9\u6cd5\u5305\u62ec\u5947\u5f02\u503c\u5206\u89e3\uff08SVD\uff09\u3001QR\u5206\u89e3\u548cLU\u5206\u89e3\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>from scipy.linalg import svd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5927\u578b\u77e9\u9635<\/strong><\/h2>\n<p>shape = (1000, 1000)<\/p>\n<p>matrix = np.random.rand(*shape)<\/p>\n<h2><strong>\u8fdb\u884c\u5947\u5f02\u503c\u5206\u89e3<\/strong><\/h2>\n<p>U, S, V = svd(matrix)<\/p>\n<h2><strong>\u4f7f\u7528\u5206\u89e3\u7ed3\u679c\u8fdb\u884c\u8ba1\u7b97<\/strong><\/h2>\n<p>result = np.dot(U, np.dot(np.diag(S), V))<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4f7f\u7528\u5206\u6cbb\u7b97\u6cd5<\/h2>\n<\/p>\n<p><p>\u5206\u6cbb\u7b97\u6cd5\u662f\u4e00\u79cd\u5c06\u95ee\u9898\u5212\u5206\u4e3a\u591a\u4e2a\u5b50\u95ee\u9898\uff0c\u5e76\u5206\u522b\u89e3\u51b3\u8fd9\u4e9b\u5b50\u95ee\u9898\u7684\u65b9\u6cd5\u3002\u5728\u5904\u7406\u5927\u578b\u77e9\u9635\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5206\u6cbb\u7b97\u6cd5\u5c06\u77e9\u9635\u5212\u5206\u4e3a\u591a\u4e2a\u5c0f\u5757\uff0c\u5e76\u9010\u5757\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5927\u578b\u77e9\u9635<\/strong><\/h2>\n<p>shape = (10000, 10000)<\/p>\n<p>matrix = np.random.rand(*shape)<\/p>\n<h2><strong>\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570<\/strong><\/h2>\n<p>def process_block(block):<\/p>\n<p>    return block.mean()<\/p>\n<h2><strong>\u4f7f\u7528\u5206\u6cbb\u7b97\u6cd5\u8fdb\u884c\u5904\u7406<\/strong><\/h2>\n<p>def process_matrix(matrix, block_size):<\/p>\n<p>    if matrix.shape[0] &lt;= block_size:<\/p>\n<p>        return process_block(matrix)<\/p>\n<p>    else:<\/p>\n<p>        mid = matrix.shape[0] \/\/ 2<\/p>\n<p>        top = process_matrix(matrix[:mid], block_size)<\/p>\n<p>        bottom = process_matrix(matrix[mid:], block_size)<\/p>\n<p>        return (top + bottom) \/ 2<\/p>\n<h2><strong>\u6267\u884c\u8ba1\u7b97<\/strong><\/h2>\n<p>result = process_matrix(matrix, 1000)<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e03\u3001\u5b58\u50a8\u548c\u52a0\u8f7d\u6570\u636e<\/strong><\/h2>\n<p><p>\u5728\u5904\u7406\u5927\u578b\u77e9\u9635\u65f6\uff0c\u9009\u62e9\u5408\u9002\u7684\u5b58\u50a8\u548c\u52a0\u8f7d\u6570\u636e\u7684\u65b9\u6cd5\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u5904\u7406\u6548\u7387\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u5b58\u50a8\u548c\u52a0\u8f7d\u6570\u636e\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h2>\u4f7f\u7528HDF5\u6587\u4ef6<\/h2>\n<\/p>\n<p><p>HDF5\u662f\u4e00\u79cd\u7528\u4e8e\u5b58\u50a8\u548c\u7ba1\u7406\u5927\u89c4\u6a21\u6570\u636e\u7684\u6587\u4ef6\u683c\u5f0f\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>h5py<\/code>\u5e93\u5c06\u5927\u578b\u77e9\u9635\u5b58\u50a8\u5728HDF5\u6587\u4ef6\u4e2d\uff0c\u5e76\u901a\u8fc7\u64cd\u4f5cHDF5\u6587\u4ef6\u5bf9\u8c61\u6765\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import h5py<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aHDF5\u6587\u4ef6<\/strong><\/h2>\n<p>filename = &#39;large_matrix.h5&#39;<\/p>\n<p>with h5py.File(filename, &#39;w&#39;) as f:<\/p>\n<p>    shape = (10000, 10000)<\/p>\n<p>    dtype = &#39;float32&#39;<\/p>\n<p>    # \u521b\u5efa\u4e00\u4e2a\u6570\u636e\u96c6<\/p>\n<p>    dataset = f.create_dataset(&#39;matrix&#39;, shape=shape, dtype=dtype)<\/p>\n<p>    # \u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e<\/p>\n<p>    dataset[0, 0] = 1.0<\/p>\n<p>    dataset[9999, 9999] = 2.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4f7f\u7528Parquet\u6587\u4ef6<\/h2>\n<\/p>\n<p><p>Parquet\u662f\u4e00\u79cd\u5217\u5f0f\u5b58\u50a8\u6587\u4ef6\u683c\u5f0f\uff0c\u9002\u7528\u4e8e\u5927\u89c4\u6a21\u6570\u636e\u5b58\u50a8\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>pyarrow<\/code>\u5e93\u5c06\u5927\u578b\u77e9\u9635\u5b58\u50a8\u5728Parquet\u6587\u4ef6\u4e2d\uff0c\u5e76\u901a\u8fc7\u64cd\u4f5cParquet\u6587\u4ef6\u5bf9\u8c61\u6765\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pyarrow as pa<\/p>\n<p>import pyarrow.parquet as pq<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5927\u578b\u77e9\u9635<\/strong><\/h2>\n<p>shape = (10000, 10000)<\/p>\n<p>matrix = np.random.rand(*shape)<\/p>\n<h2><strong>\u5c06\u77e9\u9635\u8f6c\u6362\u4e3aPyArrow\u8868<\/strong><\/h2>\n<p>table = pa.Table.from_arrays([pa.array(matrix[:, i]) for i in range(matrix.shape[1])], names=[str(i) for i in range(matrix.shape[1])])<\/p>\n<h2><strong>\u5c06\u8868\u5b58\u50a8\u4e3aParquet\u6587\u4ef6<\/strong><\/h2>\n<p>filename = &#39;large_matrix.parquet&#39;<\/p>\n<p>pq.write_table(table, filename)<\/p>\n<h2><strong>\u8bfb\u53d6Parquet\u6587\u4ef6<\/strong><\/h2>\n<p>table = pq.read_table(filename)<\/p>\n<p>print(table)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4f7f\u7528Zarr\u5e93<\/h2>\n<\/p>\n<p><p>Zarr\u662f\u4e00\u79cd\u7528\u4e8e\u5b58\u50a8\u548c\u7ba1\u7406\u5927\u89c4\u6a21\u6570\u636e\u7684\u6587\u4ef6\u683c\u5f0f\uff0c\u652f\u6301\u5e76\u884c\u8bfb\u5199\u548c\u538b\u7f29\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>zarr<\/code>\u5e93\u5c06\u5927\u578b\u77e9\u9635\u5b58\u50a8\u5728Zarr\u6587\u4ef6\u4e2d\uff0c\u5e76\u901a\u8fc7\u64cd\u4f5cZarr\u6587\u4ef6\u5bf9\u8c61\u6765\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import zarr<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aZarr\u6587\u4ef6<\/strong><\/h2>\n<p>filename = &#39;large_matrix.zarr&#39;<\/p>\n<p>shape = (10000, 10000)<\/p>\n<p>dtype = &#39;float32&#39;<\/p>\n<p>root = zarr.open(filename, mode=&#39;w&#39;)<\/p>\n<p>matrix = root.zeros(&#39;matrix&#39;, shape=shape, dtype=dtype)<\/p>\n<h2><strong>\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e<\/strong><\/h2>\n<p>matrix[0, 0] = 1.0<\/p>\n<p>matrix[9999, 9999] = 2.0<\/p>\n<h2><strong>\u4fdd\u5b58\u4fee\u6539\u5e76\u5173\u95edZarr\u6587\u4ef6<\/strong><\/h2>\n<p>root.store.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u516b\u3001\u538b\u7f29\u6570\u636e<\/strong><\/h2>\n<p><p>\u5728\u5904\u7406\u5927\u578b\u77e9\u9635\u65f6\uff0c\u538b\u7f29\u6570\u636e\u53ef\u4ee5\u663e\u8457\u51cf\u5c11\u5b58\u50a8\u7a7a\u95f4\u548c\u4f20\u8f93\u65f6\u95f4\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u6570\u636e\u538b\u7f29\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h2>\u4f7f\u7528gzip\u538b\u7f29<\/h2>\n<\/p>\n<p><p>gzip\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u6570\u636e\u538b\u7f29\u683c\u5f0f\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>gzip<\/code>\u5e93\u5c06\u5927\u578b\u77e9\u9635\u538b\u7f29\u5b58\u50a8\u5728gzip\u6587\u4ef6\u4e2d\uff0c\u5e76\u901a\u8fc7\u64cd\u4f5cgzip\u6587\u4ef6\u5bf9\u8c61\u6765\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import gzip<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5927\u578b\u77e9\u9635<\/strong><\/h2>\n<p>shape = (10000, 10000)<\/p>\n<p>matrix = np.random.rand(*shape)<\/p>\n<h2><strong>\u5c06\u77e9\u9635\u538b\u7f29\u5b58\u50a8\u5728gzip\u6587\u4ef6\u4e2d<\/strong><\/h2>\n<p>filename = &#39;large_matrix.npy.gz&#39;<\/p>\n<p>with gzip.GzipFile(filename, &#39;w&#39;) as f:<\/p>\n<p>    np.save(f, matrix)<\/p>\n<h2><strong>\u4ecegzip\u6587\u4ef6\u4e2d\u8bfb\u53d6\u77e9\u9635<\/strong><\/h2>\n<p>with gzip.GzipFile(filename, &#39;r&#39;) as f:<\/p>\n<p>    matrix = np.load(f)<\/p>\n<p>print(matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4f7f\u7528Blosc\u538b\u7f29<\/h2>\n<\/p>\n<p><p>Blosc\u662f\u4e00\u79cd\u9ad8\u6027\u80fd\u7684\u6570\u636e\u538b\u7f29\u5e93\uff0c\u9002\u7528\u4e8e\u5927\u89c4\u6a21\u6570\u636e\u538b\u7f29\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>blosc<\/code>\u5e93\u5c06\u5927\u578b\u77e9\u9635\u538b\u7f29\u5b58\u50a8\u5728Blosc\u6587\u4ef6\u4e2d\uff0c\u5e76\u901a\u8fc7\u64cd\u4f5cBlosc\u6587\u4ef6\u5bf9\u8c61\u6765\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import blosc<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5927\u578b\u77e9\u9635<\/strong><\/h2>\n<p>shape = (10000, 10000)<\/p>\n<p>matrix = np.random.rand(*shape)<\/p>\n<h2><strong>\u5c06\u77e9\u9635\u538b\u7f29\u5b58\u50a8\u5728Blosc\u6587\u4ef6\u4e2d<\/strong><\/h2>\n<p>filename = &#39;large_matrix.blosc&#39;<\/p>\n<p>compressed_matrix = blosc.compress(matrix, typesize=matrix.itemsize)<\/p>\n<p>with open(filename, &#39;wb&#39;) as f:<\/p>\n<p>    f.write(compressed_matrix)<\/p>\n<h2><strong>\u4eceBlosc\u6587\u4ef6\u4e2d\u8bfb\u53d6\u77e9\u9635<\/strong><\/h2>\n<p>with open(filename, &#39;rb&#39;) as f:<\/p>\n<p>    compressed_matrix = f.read()<\/p>\n<p>    matrix = blosc.decompress(compressed_matrix)<\/p>\n<p>    matrix = np.frombuffer(matrix, dtype=&#39;float64&#39;).reshape(shape)<\/p>\n<p>print(matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4f7f\u7528BZ2\u538b\u7f29<\/h2>\n<\/p>\n<p><p>BZ2\u662f\u4e00\u79cd\u9ad8\u6548\u7684\u6570\u636e\u538b\u7f29\u683c\u5f0f\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>bz2<\/code>\u5e93\u5c06\u5927\u578b\u77e9\u9635\u538b\u7f29\u5b58\u50a8\u5728BZ2\u6587\u4ef6\u4e2d\uff0c\u5e76\u901a\u8fc7\u64cd\u4f5cBZ2\u6587\u4ef6\u5bf9\u8c61\u6765\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import bz2<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5927\u578b\u77e9\u9635<\/strong><\/h2>\n<p>shape = (10000, 10000)<\/p>\n<p>matrix = np.random.rand(*shape)<\/p>\n<h2><strong>\u5c06\u77e9\u9635\u538b\u7f29\u5b58\u50a8\u5728BZ2\u6587\u4ef6\u4e2d<\/strong><\/h2>\n<p>filename = &#39;large_matrix.npy.bz2&#39;<\/p>\n<p>with bz2.BZ2File(filename, &#39;w&#39;) as f:<\/p>\n<p>    np.save(f, matrix)<\/p>\n<h2><strong>\u4eceBZ2\u6587\u4ef6\u4e2d\u8bfb\u53d6\u77e9\u9635<\/strong><\/h2>\n<p>with bz2.BZ2File(filename, &#39;r&#39;) as f:<\/p>\n<p>    matrix = np.load(f)<\/p>\n<p>print(matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e5d\u3001\u603b\u7ed3<\/strong><\/h2>\n<p><p>\u5904\u7406\u5927\u578b\u77e9\u9635\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u6280\u672f\u548c\u65b9\u6cd5\u6765\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\u548c\u8282\u7701\u5185\u5b58\u7a7a\u95f4\u3002<strong>\u5206\u5e03\u5f0f\u8ba1\u7b97<\/strong>\u3001<strong>\u5185\u5b58\u6620\u5c04<\/strong>\u3001<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u9ad8\u6548\u5904\u7406\u5927\u578b\u77e9\u9635\uff1f<\/strong><br \/>\u5728\u5904\u7406\u5927\u578b\u77e9\u9635\u65f6\uff0c\u9009\u62e9\u5408\u9002\u7684\u5e93\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u4f7f\u7528NumPy\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u6570\u7ec4\u64cd\u4f5c\u548c\u8ba1\u7b97\u529f\u80fd\u3002\u6b64\u5916\uff0c\u8003\u8651\u4f7f\u7528SciPy\u5e93\uff0c\u5b83\u5305\u542b\u8bb8\u591a\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u7684\u5de5\u5177\u548c\u7b97\u6cd5\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u7a00\u758f\u77e9\u9635\u65f6\u8868\u73b0\u51fa\u8272\u3002\u8fd8\u53ef\u4ee5\u5229\u7528Dask\u5e93\u6765\u5904\u7406\u8d85\u51fa\u5185\u5b58\u9650\u5236\u7684\u6570\u636e\u96c6\uff0c\u5b83\u5141\u8bb8\u7528\u6237\u5c06\u8ba1\u7b97\u4efb\u52a1\u5206\u5e03\u5230\u591a\u4e2a\u6838\u5fc3\u6216\u8282\u70b9\u4e0a\uff0c\u4ece\u800c\u63d0\u9ad8\u5904\u7406\u6548\u7387\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u600e\u6837\u51cf\u5c11\u5185\u5b58\u6d88\u8017\u4ee5\u5904\u7406\u5927\u77e9\u9635\uff1f<\/strong><br \/>\u51cf\u5c11\u5185\u5b58\u6d88\u8017\u7684\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528\u5408\u9002\u7684\u6570\u636e\u7c7b\u578b\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>float32<\/code>\u4ee3\u66ff\u9ed8\u8ba4\u7684<code>float64<\/code>\u53ef\u4ee5\u663e\u8457\u964d\u4f4e\u5185\u5b58\u5360\u7528\u3002\u53e6\u5916\uff0c\u53ef\u4ee5\u8003\u8651\u5c06\u77e9\u9635\u5b58\u50a8\u4e3a\u7a00\u758f\u683c\u5f0f\uff0c\u4ec5\u5b58\u50a8\u975e\u96f6\u5143\u7d20\uff0c\u8fd9\u6837\u53ef\u4ee5\u5927\u5927\u8282\u7701\u5185\u5b58\u3002\u4f7f\u7528\u50cf<code>scipy.sparse<\/code>\u8fd9\u6837\u7684\u5e93\u6765\u5904\u7406\u7a00\u758f\u77e9\u9635\uff0c\u6709\u52a9\u4e8e\u9ad8\u6548\u5b58\u50a8\u548c\u8ba1\u7b97\u3002<\/p>\n<p><strong>\u662f\u5426\u6709\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u53ef\u89c6\u5316\u5927\u578b\u77e9\u9635\u6570\u636e\uff1f<\/strong><br \/>\u662f\u7684\uff0c\u6709\u591a\u79cd\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u53ef\u89c6\u5316\u5927\u578b\u77e9\u9635\u6570\u636e\u3002Matplotlib\u548cSeaborn\u662f\u4e24\u4e2a\u5e38\u7528\u7684Python\u5e93\uff0c\u80fd\u591f\u521b\u5efa\u591a\u79cd\u56fe\u5f62\u4ee5\u663e\u793a\u77e9\u9635\u6570\u636e\u7684\u5206\u5e03\u548c\u7ed3\u6784\u3002\u5bf9\u4e8e\u66f4\u590d\u6742\u7684\u53ef\u89c6\u5316\u9700\u6c42\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528Plotly\uff0c\u5b83\u652f\u6301\u4ea4\u4e92\u5f0f\u56fe\u5f62\uff0c\u4fbf\u4e8e\u7528\u6237\u63a2\u7d22\u5927\u578b\u6570\u636e\u96c6\u3002\u6b64\u5916\uff0c\u4f7f\u7528Pandas DataFrame\u53ef\u4ee5\u65b9\u4fbf\u5730\u5904\u7406\u548c\u53ef\u89c6\u5316\u8868\u683c\u6570\u636e\uff0c\u7279\u522b\u662f\u5728\u7ed3\u5408\u7ed8\u56fe\u529f\u80fd\u65f6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5904\u7406\u5927\u578b\u77e9\u9635\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5206\u5e03\u5f0f\u8ba1\u7b97\u3001\u5185\u5b58\u6620\u5c04\u3001\u7a00\u758f\u77e9\u9635\u3001\u5206\u5757\u5904\u7406\u7b49\u65b9\u6cd5\u3002\u4f8b\u5982\uff0c\u5185\u5b58\u6620\u5c04\u6280\u672f\u53ef\u4ee5\u5c06\u5927 [&hellip;]","protected":false},"author":3,"featured_media":1174786,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1174781"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1174781"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1174781\/revisions"}],"predecessor-version":[{"id":1174787,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1174781\/revisions\/1174787"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1174786"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1174781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1174781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1174781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}