{"id":1101692,"date":"2025-01-08T15:52:11","date_gmt":"2025-01-08T07:52:11","guid":{"rendered":""},"modified":"2025-01-08T15:52:13","modified_gmt":"2025-01-08T07:52:13","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e5%b0%86%e5%90%91%e9%87%8f%e8%bd%ac%e5%8c%96%e4%b8%ba%e5%88%97%e8%a1%a8-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1101692.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u5c06\u5411\u91cf\u8f6c\u5316\u4e3a\u5217\u8868"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25064331\/82bd961f-8569-415d-8d96-9e7bb8da01b2.webp\" alt=\"python\u4e2d\u5982\u4f55\u5c06\u5411\u91cf\u8f6c\u5316\u4e3a\u5217\u8868\" \/><\/p>\n<p><p> \u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u5c06\u5411\u91cf\u8f6c\u6362\u4e3a\u5217\u8868\u3002<strong>\u5e38\u89c1\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528<code>tolist()<\/code>\u65b9\u6cd5\u3001<code>list()<\/code>\u51fd\u6570\u3001\u5217\u8868\u63a8\u5bfc\u5f0f<\/strong>\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u6bcf\u79cd\u65b9\u6cd5\uff0c\u5e76\u8bf4\u660e\u5176\u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528<code>tolist()<\/code>\u65b9\u6cd5<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u5411\u91cf\u662f\u4f7f\u7528NumPy\u5e93\u521b\u5efa\u7684NumPy\u6570\u7ec4\uff0c\u90a3\u4e48\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528NumPy\u6570\u7ec4\u7684<code>tolist()<\/code>\u65b9\u6cd5\u5c06\u5176\u8f6c\u6362\u4e3aPython\u5217\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aNumPy\u6570\u7ec4<\/strong><\/h2>\n<p>vector = np.array([1, 2, 3, 4, 5])<\/p>\n<h2><strong>\u5c06NumPy\u6570\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868<\/strong><\/h2>\n<p>vector_list = vector.tolist()<\/p>\n<p>print(vector_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u9996\u5148\u5bfc\u5165NumPy\u5e93\uff0c\u7136\u540e\u521b\u5efa\u4e00\u4e2aNumPy\u6570\u7ec4<code>vector<\/code>\u3002\u63a5\u7740\uff0c\u4f7f\u7528<code>tolist()<\/code>\u65b9\u6cd5\u5c06NumPy\u6570\u7ec4\u8f6c\u6362\u4e3aPython\u5217\u8868\uff0c\u5e76\u5c06\u7ed3\u679c\u5b58\u50a8\u5728<code>vector_list<\/code>\u4e2d\u3002\u6700\u540e\uff0c\u6253\u5370\u8f6c\u6362\u540e\u7684\u5217\u8868\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528<code>list()<\/code>\u51fd\u6570<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u5411\u91cf\u662f\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\uff08\u4f8b\u5982\uff0cNumPy\u6570\u7ec4\u3001\u5143\u7ec4\u3001\u96c6\u5408\u7b49\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>list()<\/code>\u51fd\u6570\u5c06\u5176\u8f6c\u6362\u4e3a\u5217\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aNumPy\u6570\u7ec4<\/strong><\/h2>\n<p>vector = np.array([1, 2, 3, 4, 5])<\/p>\n<h2><strong>\u4f7f\u7528list()\u51fd\u6570\u5c06NumPy\u6570\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868<\/strong><\/h2>\n<p>vector_list = list(vector)<\/p>\n<p>print(vector_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u4f7f\u7528<code>list()<\/code>\u51fd\u6570\u5c06NumPy\u6570\u7ec4<code>vector<\/code>\u8f6c\u6362\u4e3aPython\u5217\u8868\uff0c\u5e76\u5c06\u7ed3\u679c\u5b58\u50a8\u5728<code>vector_list<\/code>\u4e2d\u3002\u6700\u540e\uff0c\u6253\u5370\u8f6c\u6362\u540e\u7684\u5217\u8868\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u5411\u91cf\u662f\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\uff08\u4f8b\u5982\uff0cNumPy\u6570\u7ec4\u3001\u5143\u7ec4\u3001\u96c6\u5408\u7b49\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u5c06\u5176\u8f6c\u6362\u4e3a\u5217\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aNumPy\u6570\u7ec4<\/strong><\/h2>\n<p>vector = np.array([1, 2, 3, 4, 5])<\/p>\n<h2><strong>\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u5c06NumPy\u6570\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868<\/strong><\/h2>\n<p>vector_list = [element for element in vector]<\/p>\n<p>print(vector_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u904d\u5386NumPy\u6570\u7ec4<code>vector<\/code>\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u65b0\u7684\u5217\u8868\u4e2d\u3002\u6700\u7ec8\uff0c\u7ed3\u679c\u5b58\u50a8\u5728<code>vector_list<\/code>\u4e2d\uff0c\u5e76\u6253\u5370\u8f6c\u6362\u540e\u7684\u5217\u8868\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u4f7f\u7528 NumPy \u5e93<\/h2>\n<\/p>\n<p><p>NumPy \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u6570\u636e\u79d1\u5b66\u548c\u5de5\u7a0b\u4e2d\u3002\u5b83\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u6570\u7ec4\u64cd\u4f5c\u529f\u80fd\uff0c\u5e76\u4e14\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06NumPy\u6570\u7ec4\u8f6c\u6362\u4e3aPython\u5217\u8868\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u521b\u5efa NumPy \u6570\u7ec4<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aNumPy\u6570\u7ec4<\/strong><\/h2>\n<p>vector = np.array([1, 2, 3, 4, 5])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528 <code>tolist()<\/code> \u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>NumPy \u6570\u7ec4\u6709\u4e00\u4e2a\u5185\u7f6e\u7684 <code>tolist()<\/code> \u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c06NumPy\u6570\u7ec4\u8f6c\u6362\u4e3aPython\u5217\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5c06NumPy\u6570\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868<\/p>\n<p>vector_list = vector.tolist()<\/p>\n<p>print(vector_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u4f7f\u7528 <code>list()<\/code> \u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u5185\u7f6e\u7684 <code>list()<\/code> \u51fd\u6570\u4e5f\u53ef\u4ee5\u5c06NumPy\u6570\u7ec4\u8f6c\u6362\u4e3aPython\u5217\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528list()\u51fd\u6570\u5c06NumPy\u6570\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868<\/p>\n<p>vector_list = list(vector)<\/p>\n<p>print(vector_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4\u3001\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f<\/h3>\n<\/p>\n<p><p>\u5217\u8868\u63a8\u5bfc\u5f0f\u662f\u4e00\u79cd\u7b80\u6d01\u7684\u8bed\u6cd5\uff0c\u53ef\u4ee5\u5c06NumPy\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u9010\u4e00\u6dfb\u52a0\u5230\u65b0\u5217\u8868\u4e2d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u5c06NumPy\u6570\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868<\/p>\n<p>vector_list = [element for element in vector]<\/p>\n<p>print(vector_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528 Pandas \u5e93<\/h2>\n<\/p>\n<p><p>Pandas \u662f\u53e6\u4e00\u4e2a\u5e7f\u6cdb\u4f7f\u7528\u7684\u6570\u636e\u5206\u6790\u5e93\uff0c\u901a\u5e38\u7528\u4e8e\u5904\u7406\u6570\u636e\u6846\u548c\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u3002Pandas \u4e5f\u63d0\u4f9b\u4e86\u5c06\u5411\u91cf\u8f6c\u6362\u4e3a\u5217\u8868\u7684\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u521b\u5efa Pandas \u7cfb\u5217<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aPandas\u7cfb\u5217<\/strong><\/h2>\n<p>vector = pd.Series([1, 2, 3, 4, 5])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528 <code>tolist()<\/code> \u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>Pandas \u7cfb\u5217\u4e5f\u6709\u4e00\u4e2a\u5185\u7f6e\u7684 <code>tolist()<\/code> \u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c06\u5176\u8f6c\u6362\u4e3aPython\u5217\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5c06Pandas\u7cfb\u5217\u8f6c\u6362\u4e3a\u5217\u8868<\/p>\n<p>vector_list = vector.tolist()<\/p>\n<p>print(vector_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528 Python \u5185\u7f6e\u51fd\u6570\u548c\u65b9\u6cd5<\/h2>\n<\/p>\n<p><p>\u6709\u65f6\uff0c\u5411\u91cf\u53ef\u80fd\u662f\u4ee5\u5176\u4ed6\u5f62\u5f0f\u5b58\u5728\u7684\uff0c\u5982\u5143\u7ec4\u6216\u96c6\u5408\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u5185\u7f6e\u51fd\u6570\u548c\u65b9\u6cd5\u5c06\u8fd9\u4e9b\u5411\u91cf\u8f6c\u6362\u4e3a\u5217\u8868\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u8f6c\u6362\u5143\u7ec4<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u5143\u7ec4<\/p>\n<p>vector = (1, 2, 3, 4, 5)<\/p>\n<h2><strong>\u4f7f\u7528list()\u51fd\u6570\u5c06\u5143\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868<\/strong><\/h2>\n<p>vector_list = list(vector)<\/p>\n<p>print(vector_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u8f6c\u6362\u96c6\u5408<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u96c6\u5408<\/p>\n<p>vector = {1, 2, 3, 4, 5}<\/p>\n<h2><strong>\u4f7f\u7528list()\u51fd\u6570\u5c06\u96c6\u5408\u8f6c\u6362\u4e3a\u5217\u8868<\/strong><\/h2>\n<p>vector_list = list(vector)<\/p>\n<p>print(vector_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u56db\u3001\u4f7f\u7528 SciPy \u5e93<\/h2>\n<\/p>\n<p><p>SciPy \u662f\u4e00\u4e2a\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u7684\u5e93\uff0c\u63d0\u4f9b\u4e86\u8bb8\u591a\u9ad8\u7ea7\u6570\u5b66\u51fd\u6570\u3002\u5b83\u4e5f\u53ef\u4ee5\u7528\u4e8e\u5c06\u5411\u91cf\u8f6c\u6362\u4e3a\u5217\u8868\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u521b\u5efa SciPy \u7a00\u758f\u77e9\u9635<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\">from scipy.sparse import csr_matrix<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aSciPy\u7a00\u758f\u77e9\u9635<\/strong><\/h2>\n<p>vector = csr_matrix([1, 2, 3, 4, 5])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u5c06\u7a00\u758f\u77e9\u9635\u8f6c\u6362\u4e3a\u5217\u8868<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5c06\u7a00\u758f\u77e9\u9635\u8f6c\u6362\u4e3a\u6570\u7ec4<\/p>\n<p>vector_array = vector.toarray()<\/p>\n<h2><strong>\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868<\/strong><\/h2>\n<p>vector_list = vector_array.tolist()[0]<\/p>\n<p>print(vector_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u9996\u5148\u521b\u5efa\u4e00\u4e2aSciPy\u7a00\u758f\u77e9\u9635<code>vector<\/code>\uff0c\u7136\u540e\u4f7f\u7528<code>toarray()<\/code>\u65b9\u6cd5\u5c06\u5176\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4\u3002\u63a5\u7740\uff0c\u4f7f\u7528<code>tolist()<\/code>\u65b9\u6cd5\u5c06NumPy\u6570\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868\u3002\u7531\u4e8e\u7a00\u758f\u77e9\u9635\u8f6c\u6362\u540e\u7684\u6570\u7ec4\u662f\u4e8c\u7ef4\u7684\uff0c\u9700\u8981\u901a\u8fc7\u7d22\u5f15<code>[0]<\/code>\u83b7\u53d6\u5b9e\u9645\u7684\u5411\u91cf\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u4f7f\u7528 TensorFlow \u5e93<\/h2>\n<\/p>\n<p><p>TensorFlow \u662f\u4e00\u4e2a\u5e7f\u6cdb\u5e94\u7528\u4e8e<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u548c\u6df1\u5ea6\u5b66\u4e60\u7684\u5e93\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528TensorFlow\u5c06\u5f20\u91cf\u8f6c\u6362\u4e3a\u5217\u8868\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u521b\u5efa TensorFlow \u5f20\u91cf<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\">import tensorflow as tf<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aTensorFlow\u5f20\u91cf<\/strong><\/h2>\n<p>vector = tf.constant([1, 2, 3, 4, 5])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u5c06\u5f20\u91cf\u8f6c\u6362\u4e3a\u5217\u8868<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5c06TensorFlow\u5f20\u91cf\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4<\/p>\n<p>vector_array = vector.numpy()<\/p>\n<h2><strong>\u5c06NumPy\u6570\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868<\/strong><\/h2>\n<p>vector_list = vector_array.tolist()<\/p>\n<p>print(vector_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u9996\u5148\u521b\u5efa\u4e00\u4e2aTensorFlow\u5f20\u91cf<code>vector<\/code>\uff0c\u7136\u540e\u4f7f\u7528<code>numpy()<\/code>\u65b9\u6cd5\u5c06\u5176\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4\u3002\u63a5\u7740\uff0c\u4f7f\u7528<code>tolist()<\/code>\u65b9\u6cd5\u5c06NumPy\u6570\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868\u3002<\/p>\n<\/p>\n<p><h2>\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u4e86Python\u4e2d\u5c06\u5411\u91cf\u8f6c\u6362\u4e3a\u5217\u8868\u7684\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528NumPy\u5e93\u3001Pandas\u5e93\u3001Python\u5185\u7f6e\u51fd\u6570\u548c\u65b9\u6cd5\u3001SciPy\u5e93\u4ee5\u53caTensorFlow\u5e93\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u7279\u5b9a\u7684\u5e94\u7528\u573a\u666f\u548c\u4f18\u52bf\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53ef\u4ee5\u4f7f\u4ee3\u7801\u66f4\u52a0\u7b80\u6d01\u3001\u9ad8\u6548\u3002<\/p>\n<\/p>\n<p><p><strong>\u63a8\u8350\u4f7f\u7528NumPy\u5e93\u7684<code>tolist()<\/code>\u65b9\u6cd5\u548c\u5185\u7f6e\u7684<code>list()<\/code>\u51fd\u6570<\/strong>\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e0d\u4ec5\u7b80\u5355\u6613\u7528\uff0c\u800c\u4e14\u9002\u7528\u4e8e\u5927\u591a\u6570\u60c5\u51b5\u3002\u5982\u679c\u5411\u91cf\u662f\u4ee5\u5176\u4ed6\u5f62\u5f0f\u5b58\u5728\u7684\uff0c\u5982Pandas\u7cfb\u5217\u3001\u7a00\u758f\u77e9\u9635\u6216\u5f20\u91cf\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u76f8\u5e94\u5e93\u63d0\u4f9b\u7684\u8f6c\u6362\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u638c\u63e1\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u60a8\u5c06\u80fd\u591f\u66f4\u52a0\u7075\u6d3b\u5730\u5904\u7406\u6570\u636e\uff0c\u5e76\u5728\u6570\u636e\u5206\u6790\u548c\u79d1\u5b66\u8ba1\u7b97\u4e2d\u5f97\u5fc3\u5e94\u624b\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5c06NumPy\u5411\u91cf\u8f6c\u6362\u4e3a\u5217\u8868\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u4f7f\u7528NumPy\u5e93\u7684\u5411\u91cf\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528<code>.tolist()<\/code>\u65b9\u6cd5\u8f7b\u677e\u8f6c\u6362\u4e3a\u5217\u8868\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u6709\u4e00\u4e2aNumPy\u5411\u91cf<code>v = np.array([1, 2, 3])<\/code>\uff0c\u53ef\u4ee5\u4f7f\u7528<code>list_v = v.tolist()<\/code>\u5c06\u5176\u8f6c\u6362\u4e3a\u5217\u8868<code>[1, 2, 3]<\/code>\u3002\u8fd9\u79cd\u65b9\u6cd5\u4fdd\u6301\u4e86\u5411\u91cf\u4e2d\u5143\u7d20\u7684\u987a\u5e8f\u548c\u7c7b\u578b\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\uff0c\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u53ef\u4ee5\u5982\u4f55\u8f6c\u6362\u5411\u91cf\uff1f<\/strong><br \/>\u5217\u8868\u63a8\u5bfc\u5f0f\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u5141\u8bb8\u7528\u6237\u4ee5\u7b80\u6d01\u7684\u65b9\u5f0f\u751f\u6210\u5217\u8868\u3002\u5982\u679c\u4f60\u6709\u4e00\u4e2aNumPy\u5411\u91cf<code>v<\/code>\uff0c\u53ef\u4ee5\u901a\u8fc7<code>list_v = [x for x in v]<\/code>\u5c06\u5176\u8f6c\u6362\u4e3a\u5217\u8868\u3002\u8fd9\u79cd\u65b9\u6cd5\u540c\u6837\u4f1a\u4fdd\u7559\u5143\u7d20\u7684\u987a\u5e8f\uff0c\u975e\u5e38\u9002\u5408\u5bf9\u5411\u91cf\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u8fdb\u884c\u5904\u7406\u6216\u8f6c\u6362\u65f6\u4f7f\u7528\u3002<\/p>\n<p><strong>\u8f6c\u6362\u5411\u91cf\u4e3a\u5217\u8868\u65f6\uff0c\u662f\u5426\u4f1a\u4e22\u5931\u6570\u636e\u7c7b\u578b\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u5c06NumPy\u5411\u91cf\u8f6c\u6362\u4e3a\u5217\u8868\u65f6\uff0c\u5143\u7d20\u7684\u7c7b\u578b\u901a\u5e38\u4e0d\u4f1a\u4e22\u5931\uff0c\u4f46\u4f1a\u6839\u636e\u5217\u8868\u7684\u7279\u6027\u8fdb\u884c\u8f6c\u6362\u3002\u4f8b\u5982\uff0c\u82e5\u539f\u5411\u91cf\u7684\u6570\u636e\u7c7b\u578b\u4e3a\u6d6e\u70b9\u6570\uff0c\u8f6c\u6362\u540e\u7684\u5217\u8868\u4ecd\u4f1a\u4fdd\u7559\u6d6e\u70b9\u6570\u7c7b\u578b\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u5982\u679c\u5411\u91cf\u4e2d\u5305\u542b\u4e0d\u540c\u6570\u636e\u7c7b\u578b\u7684\u5143\u7d20\uff0c\u5217\u8868\u5c06\u4f1a\u7edf\u4e00\u4e3a\u6700\u901a\u7528\u7684\u7c7b\u578b\uff0c\u53ef\u80fd\u5bfc\u81f4\u7cbe\u5ea6\u635f\u5931\u3002\u56e0\u6b64\uff0c\u8f6c\u6362\u540e\u5e94\u4ed4\u7ec6\u68c0\u67e5\u6570\u636e\u7c7b\u578b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u5c06\u5411\u91cf\u8f6c\u6362\u4e3a\u5217\u8868\u3002\u5e38\u89c1\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528tolist()\u65b9\u6cd5\u3001list()\u51fd\u6570\u3001\u5217 [&hellip;]","protected":false},"author":3,"featured_media":1101699,"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\/1101692"}],"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=1101692"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1101692\/revisions"}],"predecessor-version":[{"id":1101701,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1101692\/revisions\/1101701"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1101699"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1101692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1101692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1101692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}