{"id":954918,"date":"2024-12-27T02:06:23","date_gmt":"2024-12-26T18:06:23","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/954918.html"},"modified":"2024-12-27T02:06:25","modified_gmt":"2024-12-26T18:06:25","slug":"python%e5%a6%82%e4%bd%95%e6%89%93%e5%bc%80npy%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/954918.html","title":{"rendered":"python\u5982\u4f55\u6253\u5f00npy\u6587\u4ef6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25094950\/2d8f1c60-3333-43fc-b14e-36628ee0a8d0.webp\" alt=\"python\u5982\u4f55\u6253\u5f00npy\u6587\u4ef6\" \/><\/p>\n<p><p> <strong>Python\u6253\u5f00npy\u6587\u4ef6\u4e3b\u8981\u901a\u8fc7numpy\u5e93\u4e2d\u7684load\u51fd\u6570\u5b9e\u73b0\uff0c\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a\u5bfc\u5165numpy\u5e93\u3001\u4f7f\u7528numpy.load()\u51fd\u6570\u8bfb\u53d6npy\u6587\u4ef6\u3001\u5904\u7406\u8bfb\u53d6\u7684\u6570\u636e<\/strong>\u3002\u5bfc\u5165numpy\u5e93\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7numpy.load()\u51fd\u6570\u52a0\u8f7dnpy\u6587\u4ef6\uff0c\u52a0\u8f7d\u7684\u6570\u636e\u901a\u5e38\u662fNumPy\u6570\u7ec4\u683c\u5f0f\uff0c\u60a8\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u8fd9\u4e9b\u6570\u7ec4\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u5904\u7406\u548c\u5206\u6790\u3002\u4ee5\u4e0b\u662f\u66f4\u8be6\u7ec6\u7684\u8bf4\u660e\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001NUMPY\u5e93\u7684\u5b89\u88c5\u548c\u5bfc\u5165<\/p>\n<\/p>\n<p><p>\u5728\u5904\u7406npy\u6587\u4ef6\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u4f60\u7684Python\u73af\u5883\u4e2d\u5df2\u7ecf\u5b89\u88c5\u4e86NumPy\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u5728\u4f60\u7684Python\u811a\u672c\u4e2d\u5bfc\u5165NumPy\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>NumPy\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u652f\u6301\u5927\u91cf\u7684\u7ef4\u5ea6\u6570\u7ec4\u4e0e\u77e9\u9635\u8fd0\u7b97\uff0c\u6b64\u5916\u4e5f\u9488\u5bf9\u6570\u7ec4\u8fd0\u7b97\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u6570\u5b66\u51fd\u6570\u5e93\u3002npy\u6587\u4ef6\u683c\u5f0f\u662fNumPy\u7528\u6765\u5b58\u50a8\u5355\u4e2a\u6570\u7ec4\u7684\u6570\u636e\u683c\u5f0f\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u52a0\u8f7dNPY\u6587\u4ef6<\/p>\n<\/p>\n<p><p>\u4f7f\u7528numpy.load()\u51fd\u6570\u6765\u52a0\u8f7dnpy\u6587\u4ef6\u3002\u8fd9\u4e2a\u51fd\u6570\u53ef\u4ee5\u8bfb\u53d6\u78c1\u76d8\u4e0a\u7684npy\u6587\u4ef6\u5e76\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\u3002\u5047\u8bbe\u4f60\u6709\u4e00\u4e2a\u540d\u4e3adata.npy\u7684\u6587\u4ef6\uff0c\u53ef\u4ee5\u7528\u4ee5\u4e0b\u65b9\u6cd5\u52a0\u8f7d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = np.load(&#39;data.npy&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u52a0\u8f7d\u540e\uff0cdata\u5c06\u662f\u4e00\u4e2aNumPy\u6570\u7ec4\u3002\u4f60\u53ef\u4ee5\u67e5\u770b\u6570\u7ec4\u7684\u5f62\u72b6\u3001\u6570\u636e\u7c7b\u578b\u4ee5\u53ca\u5176\u4ed6\u5c5e\u6027\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(data.shape)<\/p>\n<p>print(data.dtype)<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>numpy.load()\u51fd\u6570\u975e\u5e38\u5f3a\u5927\uff0c\u5b83\u4e0d\u4ec5\u80fd\u591f\u52a0\u8f7dnpy\u6587\u4ef6\uff0c\u8fd8\u53ef\u4ee5\u52a0\u8f7dnpz\u6587\u4ef6\uff08\u591a\u4e2a\u6570\u7ec4\uff09\u3002\u5728\u52a0\u8f7dnpz\u6587\u4ef6\u65f6\uff0c\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u5b57\u5178\uff0c\u5b57\u5178\u7684\u952e\u662f\u6570\u7ec4\u7684\u540d\u79f0\uff0c\u503c\u662f\u6570\u7ec4\u672c\u8eab\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4e09\u3001\u5904\u7406NPY\u6587\u4ef6\u4e2d\u7684\u6570\u636e<\/p>\n<\/p>\n<p><p>\u52a0\u8f7d\u7684NumPy\u6570\u7ec4\u53ef\u4ee5\u76f4\u63a5\u7528\u4e8e\u8fdb\u4e00\u6b65\u7684\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u5904\u7406\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><p>1\u3001<strong>\u6570\u636e\u5207\u7247\u548c\u7d22\u5f15<\/strong><\/p>\n<\/p>\n<p><p>NumPy\u6570\u7ec4\u652f\u6301\u591a\u7ef4\u6570\u636e\u5207\u7247\u548c\u7d22\u5f15\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u63d0\u53d6\u6570\u7ec4\u4e2d\u7684\u7279\u5b9a\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u7b2c\u4e00\u884c\u7684\u6570\u636e<\/p>\n<p>first_row = data[0]<\/p>\n<h2><strong>\u83b7\u53d6\u524d\u4e24\u5217\u7684\u6570\u636e<\/strong><\/h2>\n<p>first_two_columns = data[:, :2]<\/p>\n<h2><strong>\u83b7\u53d6\u6240\u6709\u884c\u7684\u7b2c\u4e09\u5217\u6570\u636e<\/strong><\/h2>\n<p>third_column = data[:, 2]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>2\u3001<strong>\u6570\u7ec4\u8fd0\u7b97<\/strong><\/p>\n<\/p>\n<p><p>NumPy\u652f\u6301\u9ad8\u6548\u7684\u6570\u7ec4\u8fd0\u7b97\uff0c\u8fd9\u4f7f\u5f97\u5bf9\u6570\u636e\u7684\u6279\u91cf\u64cd\u4f5c\u53d8\u5f97\u975e\u5e38\u7b80\u5355\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u6570\u7ec4\u8fd0\u7b97\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5bf9\u6570\u7ec4\u7684\u6bcf\u4e2a\u5143\u7d20\u52a01<\/p>\n<p>data_plus_one = data + 1<\/p>\n<h2><strong>\u6c42\u6570\u7ec4\u4e2d\u6240\u6709\u5143\u7d20\u7684\u548c<\/strong><\/h2>\n<p>sum_of_elements = np.sum(data)<\/p>\n<h2><strong>\u8ba1\u7b97\u6570\u7ec4\u4e2d\u6bcf\u5217\u7684\u5747\u503c<\/strong><\/h2>\n<p>mean_of_columns = np.mean(data, axis=0)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>3\u3001<strong>\u6570\u636e\u53ef\u89c6\u5316<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u5206\u6790\u6570\u636e\u65f6\uff0c\u6570\u636e\u53ef\u89c6\u5316\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u5de5\u5177\u3002\u53ef\u4ee5\u7ed3\u5408matplotlib\u5e93\u6765\u7ed8\u5236\u6570\u636e\u7684\u56fe\u5f62\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u7ed8\u5236\u6570\u636e\u7684\u76f4\u65b9\u56fe<\/strong><\/h2>\n<p>plt.hist(data.flatten(), bins=50)<\/p>\n<p>plt.title(&#39;Histogram of Data&#39;)<\/p>\n<p>plt.xlabel(&#39;Value&#39;)<\/p>\n<p>plt.ylabel(&#39;Frequency&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u4fdd\u5b58\u5904\u7406\u540e\u7684\u6570\u636e<\/p>\n<\/p>\n<p><p>\u5904\u7406\u540e\u7684\u6570\u636e\u53ef\u4ee5\u4f7f\u7528numpy.save()\u51fd\u6570\u4fdd\u5b58\u4e3a\u65b0\u7684npy\u6587\u4ef6\u3002\u5047\u8bbe\u4f60\u5bf9\u6570\u636e\u8fdb\u884c\u4e86\u67d0\u4e9b\u5904\u7406\u5e76\u5e0c\u671b\u4fdd\u5b58\u7ed3\u679c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5047\u8bbe\u5904\u7406\u540e\u7684\u6570\u636e\u5b58\u50a8\u5728\u53d8\u91cfprocessed_data\u4e2d<\/p>\n<p>np.save(&#39;processed_data.npy&#39;, processed_data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>numpy.save()\u51fd\u6570\u4f1a\u5c06NumPy\u6570\u7ec4\u4fdd\u5b58\u5230\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6587\u4ef6\u4e2d\uff0c\u6587\u4ef6\u7684\u6269\u5c55\u540d\u901a\u5e38\u662fnpy\u3002\u8fd9\u79cd\u683c\u5f0f\u7684\u4f18\u70b9\u662f\u5b58\u50a8\u6548\u7387\u9ad8\u3001\u8bfb\u53d6\u901f\u5ea6\u5feb\uff0c\u5e76\u4e14\u80fd\u591f\u4fdd\u6301\u6570\u636e\u7c7b\u578b\u4fe1\u606f\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4e94\u3001NUMPY\u7684\u9ad8\u7ea7\u7279\u6027<\/p>\n<\/p>\n<p><p>\u5728\u5904\u7406npy\u6587\u4ef6\u7684\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u4f1a\u7528\u5230NumPy\u7684\u4e00\u4e9b\u9ad8\u7ea7\u7279\u6027\uff0c\u5982\u5e7f\u64ad\u673a\u5236\u3001\u77e2\u91cf\u5316\u8fd0\u7b97\u7b49\u3002\u8fd9\u4e9b\u7279\u6027\u4f7f\u5f97NumPy\u7684\u4f7f\u7528\u66f4\u52a0\u7075\u6d3b\u548c\u9ad8\u6548\u3002<\/p>\n<\/p>\n<p><p>1\u3001<strong>\u5e7f\u64ad\u673a\u5236<\/strong><\/p>\n<\/p>\n<p><p>\u5e7f\u64ad\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u673a\u5236\uff0c\u5b83\u80fd\u591f\u5728\u4e0d\u521b\u5efa\u65b0\u6570\u7ec4\u7684\u60c5\u51b5\u4e0b\uff0c\u5728\u4e0d\u540c\u5f62\u72b6\u7684\u6570\u7ec4\u4e4b\u95f4\u8fdb\u884c\u8fd0\u7b97\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5047\u8bbedata\u662f\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4<\/p>\n<p>row_means = np.mean(data, axis=1, keepdims=True)<\/p>\n<p>centered_data = data - row_means<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0crow_means\u662f\u4e00\u4e2a\u5217\u5411\u91cf\uff0c\u5b83\u7684\u5f62\u72b6\u4e0edata\u7684\u6bcf\u4e00\u884c\u5339\u914d\uff0c\u5e7f\u64ad\u673a\u5236\u4f7f\u5f97\u76f4\u63a5\u76f8\u51cf\u6210\u4e3a\u53ef\u80fd\u3002<\/p>\n<\/p>\n<p><p>2\u3001<strong>\u77e2\u91cf\u5316\u8fd0\u7b97<\/strong><\/p>\n<\/p>\n<p><p>\u77e2\u91cf\u5316\u8fd0\u7b97\u662f\u6307\u5728\u4e0d\u4f7f\u7528\u663e\u5f0f\u5faa\u73af\u7684\u60c5\u51b5\u4e0b\uff0c\u5bf9\u6570\u7ec4\u8fdb\u884c\u6279\u91cf\u8fd0\u7b97\u3002NumPy\u7684\u8bb8\u591a\u51fd\u6570\u90fd\u652f\u6301\u77e2\u91cf\u5316\u8fd0\u7b97\uff0c\u8fd9\u4f7f\u5f97\u4ee3\u7801\u66f4\u52a0\u7b80\u6d01\u548c\u9ad8\u6548\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u6bcf\u4e2a\u5143\u7d20\u7684\u5e73\u65b9<\/p>\n<p>squared_data = np.square(data)<\/p>\n<h2><strong>\u8ba1\u7b97\u6bcf\u4e2a\u5143\u7d20\u7684\u81ea\u7136\u5bf9\u6570<\/strong><\/h2>\n<p>log_data = np.log(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u516d\u3001\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e<\/p>\n<\/p>\n<p><p>\u5f53\u5904\u7406\u975e\u5e38\u5927\u7684npy\u6587\u4ef6\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u5185\u5b58\u4e0d\u8db3\u7684\u95ee\u9898\u3002\u6b64\u65f6\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u4ee5\u4e0b\u7b56\u7565\uff1a<\/p>\n<\/p>\n<p><p>1\u3001<strong>\u5206\u5757\u5904\u7406<\/strong><\/p>\n<\/p>\n<p><p>\u5c06\u5927\u6570\u636e\u5206\u6210\u5c0f\u5757\u8fdb\u884c\u5904\u7406\uff0c\u907f\u514d\u4e00\u6b21\u6027\u52a0\u8f7d\u6574\u4e2a\u6570\u636e\u96c6\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528numpy.memmap()\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u5185\u5b58\u6620\u5c04\u6570\u7ec4\uff0c\u53ea\u52a0\u8f7d\u9700\u8981\u5904\u7406\u7684\u90e8\u5206\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u5185\u5b58\u6620\u5c04\u6570\u7ec4<\/p>\n<p>data = np.memmap(&#39;data.npy&#39;, dtype=&#39;float32&#39;, mode=&#39;r&#39;, shape=(10000, 1000))<\/p>\n<h2><strong>\u5904\u7406\u6bcf\u4e00\u884c\u6570\u636e<\/strong><\/h2>\n<p>for i in range(data.shape[0]):<\/p>\n<p>    row = data[i]<\/p>\n<p>    # \u5bf9\u6bcf\u4e00\u884c\u7684\u6570\u636e\u8fdb\u884c\u5904\u7406<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>2\u3001<strong>\u4f7f\u7528dask\u5e93<\/strong><\/p>\n<\/p>\n<p><p>dask\u662f\u4e00\u4e2a\u5e76\u884c\u8ba1\u7b97\u5e93\uff0c\u5b83\u80fd\u591f\u5904\u7406\u6bd4\u5185\u5b58\u5927\u5f97\u591a\u7684\u6570\u636e\u96c6\u3002dask\u7684Array\u5bf9\u8c61\u652f\u6301NumPy\u7684\u8bb8\u591a\u64cd\u4f5c\uff0c\u5e76\u4e14\u80fd\u591f\u5728\u5206\u5e03\u5f0f\u73af\u5883\u4e2d\u6267\u884c\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>data = da.from_array(np.load(&#39;data.npy&#39;), chunks=(1000, 1000))<\/p>\n<h2><strong>\u8ba1\u7b97\u6bcf\u5217\u7684\u5747\u503c<\/strong><\/h2>\n<p>mean_of_columns = data.mean(axis=0).compute()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u4f7f\u7528dask\u5e93\u7684\u597d\u5904\u662f\u5b83\u80fd\u591f\u5728\u4e0d\u4fee\u6539\u592a\u591a\u4ee3\u7801\u7684\u60c5\u51b5\u4e0b\uff0c\u5c06\u8ba1\u7b97\u5206\u5e03\u5230\u591a\u4e2aCPU\u6838\u5fc3\u6216\u8282\u70b9\u4e0a\uff0c\u4ece\u800c\u52a0\u901f\u6570\u636e\u5904\u7406\u8fc7\u7a0b\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4e03\u3001NPY\u6587\u4ef6\u7684\u517c\u5bb9\u6027\u548c\u6027\u80fd\u4f18\u5316<\/p>\n<\/p>\n<p><p>1\u3001<strong>\u517c\u5bb9\u6027<\/strong><\/p>\n<\/p>\n<p><p>npy\u6587\u4ef6\u683c\u5f0f\u662fNumPy\u4e13\u6709\u7684\uff0c\u867d\u7136\u5b83\u5728Python\u79d1\u5b66\u8ba1\u7b97\u9886\u57df\u4f7f\u7528\u5e7f\u6cdb\uff0c\u4f46\u5728\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u4e2d\u53ef\u80fd\u4e0d\u88ab\u76f4\u63a5\u652f\u6301\u3002\u5982\u679c\u9700\u8981\u5728\u5176\u4ed6\u8bed\u8a00\u4e2d\u4f7f\u7528npy\u6587\u4ef6\uff0c\u53ef\u4ee5\u8003\u8651\u8f6c\u6362\u4e3a\u5176\u4ed6\u683c\u5f0f\uff0c\u5982CSV\u6216HDF5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import h5py<\/p>\n<h2><strong>\u5c06NumPy\u6570\u7ec4\u4fdd\u5b58\u4e3aHDF5\u6587\u4ef6<\/strong><\/h2>\n<p>with h5py.File(&#39;data.h5&#39;, &#39;w&#39;) as f:<\/p>\n<p>    f.create_dataset(&#39;dataset_name&#39;, data=data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>2\u3001<strong>\u6027\u80fd\u4f18\u5316<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5927\u91cf\u6570\u636e\u65f6\uff0c\u6027\u80fd\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u8003\u91cf\u56e0\u7d20\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f18\u5316\u5efa\u8bae\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528NumPy\u7684\u5185\u7f6e\u51fd\u6570\uff0c\u8fd9\u4e9b\u51fd\u6570\u901a\u5e38\u662f\u7528C\u8bed\u8a00\u5b9e\u73b0\u7684\uff0c\u901f\u5ea6\u5f88\u5feb\u3002<\/li>\n<li>\u5c3d\u91cf\u907f\u514d\u663e\u5f0f\u5faa\u73af\uff0c\u4f7f\u7528\u77e2\u91cf\u5316\u8fd0\u7b97\u4ee3\u66ff\u3002<\/li>\n<li>\u5408\u7406\u5229\u7528NumPy\u7684\u5e7f\u64ad\u673a\u5236\uff0c\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u6570\u636e\u590d\u5236\u3002<\/li>\n<li>\u5982\u679c\u5185\u5b58\u5141\u8bb8\uff0c\u4f7f\u7528float32\u800c\u4e0d\u662ffloat64\u6765\u51cf\u5c11\u6570\u636e\u5360\u7528\u7684\u7a7a\u95f4\u3002<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u7684\u4ecb\u7ecd\uff0c\u76f8\u4fe1\u60a8\u5df2\u7ecf\u5bf9\u5982\u4f55\u5728Python\u4e2d\u5904\u7406npy\u6587\u4ef6\u6709\u4e86\u4e00\u4e2a\u5168\u9762\u7684\u4e86\u89e3\u3002NumPy\u7684\u5f3a\u5927\u529f\u80fd\u548c\u7075\u6d3b\u6027\u4f7f\u5f97\u5b83\u6210\u4e3a\u5904\u7406\u79d1\u5b66\u8ba1\u7b97\u6570\u636e\u7684\u5229\u5668\uff0c\u800c\u638c\u63e1\u8fd9\u4e9b\u6280\u672f\u7ec6\u8282\u5c06\u5e2e\u52a9\u60a8\u66f4\u6709\u6548\u5730\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u5904\u7406\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8bfb\u53d6npy\u6587\u4ef6\u7684\u5185\u5bb9\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u6765\u8bfb\u53d6npy\u6587\u4ef6\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5b89\u88c5\u4e86NumPy\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8bfb\u53d6npy\u6587\u4ef6\uff1a  <\/p>\n<pre><code class=\"language-python\">import numpy as np  \ndata = np.load(&#39;your_file.npy&#39;)  \nprint(data)  \n<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u83b7\u53d6npy\u6587\u4ef6\u4e2d\u7684\u6570\u7ec4\u6570\u636e\uff0c\u5e76\u53ef\u4ee5\u5bf9\u5176\u8fdb\u884c\u8fdb\u4e00\u6b65\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u6253\u5f00npy\u6587\u4ef6\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u4e8b\u9879\uff1f<\/strong><br \/>\u5728\u6253\u5f00npy\u6587\u4ef6\u4e4b\u524d\uff0c\u786e\u4fdd\u8be5\u6587\u4ef6\u5b58\u5728\u5e76\u4e14\u8def\u5f84\u6b63\u786e\u3002\u5982\u679c\u6587\u4ef6\u8def\u5f84\u4e0d\u6b63\u786e\uff0cPython\u4f1a\u629b\u51fa\u4e00\u4e2a\u9519\u8bef\u3002\u6b64\u5916\uff0c\u786e\u4fdd\u4f7f\u7528\u7684NumPy\u7248\u672c\u4e0e\u751f\u6210npy\u6587\u4ef6\u65f6\u7684\u7248\u672c\u517c\u5bb9\uff0c\u4ee5\u907f\u514d\u6f5c\u5728\u7684\u8bfb\u53d6\u95ee\u9898\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u5904\u7406\u5927\u578bnpy\u6587\u4ef6\uff1f<\/strong><br \/>\u5bf9\u4e8e\u8f83\u5927\u7684npy\u6587\u4ef6\uff0c\u5efa\u8bae\u4f7f\u7528NumPy\u7684\u5185\u5b58\u6620\u5c04\u529f\u80fd\u3002\u8fd9\u53ef\u4ee5\u6709\u6548\u5730\u5904\u7406\u5185\u5b58\u4f7f\u7528\u95ee\u9898\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5b9e\u73b0\uff1a  <\/p>\n<pre><code class=\"language-python\">data = np.load(&#39;your_large_file.npy&#39;, mmap_mode=&#39;r&#39;)  \n<\/code><\/pre>\n<p>\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u4e00\u6b21\u6027\u5c06\u6574\u4e2a\u6587\u4ef6\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u800c\u662f\u6309\u9700\u8bbf\u95ee\u6587\u4ef6\u5185\u5bb9\uff0c\u63d0\u5347\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u6253\u5f00npy\u6587\u4ef6\u4e3b\u8981\u901a\u8fc7numpy\u5e93\u4e2d\u7684load\u51fd\u6570\u5b9e\u73b0\uff0c\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a\u5bfc\u5165numpy\u5e93\u3001\u4f7f\u7528num [&hellip;]","protected":false},"author":3,"featured_media":954923,"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\/954918"}],"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=954918"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/954918\/revisions"}],"predecessor-version":[{"id":954924,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/954918\/revisions\/954924"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/954923"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=954918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=954918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=954918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}