{"id":1154196,"date":"2025-01-13T17:48:22","date_gmt":"2025-01-13T09:48:22","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1154196.html"},"modified":"2025-01-13T17:48:25","modified_gmt":"2025-01-13T09:48:25","slug":"python%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8b%e6%95%b0%e6%8d%ae%e7%bb%b4%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1154196.html","title":{"rendered":"python\u5982\u4f55\u67e5\u770b\u6570\u636e\u7ef4\u5ea6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25183841\/f235332f-f515-4ce0-8193-cc42662971f2.webp\" alt=\"python\u5982\u4f55\u67e5\u770b\u6570\u636e\u7ef4\u5ea6\" \/><\/p>\n<p><p> \u8981\u67e5\u770bPython\u4e2d\u6570\u636e\u7684\u7ef4\u5ea6\uff0c\u53ef\u4ee5\u4f7f\u7528\u51e0\u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u6570\u636e\u7684\u7c7b\u578b\u3002<strong>\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u7684<code>ndim<\/code>\u5c5e\u6027\u548c<code>shape<\/code>\u5c5e\u6027\u3001Pandas\u5e93\u7684<code>shape<\/code>\u5c5e\u6027\u3001TensorFlow\u548cPyTorch\u7b49\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u7684\u76f8\u5173\u5c5e\u6027<\/strong>\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u6765\u67e5\u770b\u6570\u636e\u7684\u7ef4\u5ea6\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528NumPy\u67e5\u770b\u6570\u636e\u7ef4\u5ea6<\/h3>\n<\/p>\n<p><p>NumPy\u662f\u4e00\u4e2a\u6d41\u884c\u7684Python\u5e93\uff0c\u5e7f\u6cdb\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u548c\u6570\u636e\u5206\u6790\u3002NumPy\u6570\u7ec4\u662f\u4e00\u79cd\u591a\u7ef4\u6570\u7ec4\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u5b66\u8fd0\u7b97\u548c\u6570\u636e\u5904\u7406\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u67e5\u770bNumPy\u6570\u7ec4\u7ef4\u5ea6\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528<code>ndim<\/code>\u5c5e\u6027<\/h4>\n<\/p>\n<p><p>NumPy\u6570\u7ec4\u5177\u6709\u4e00\u4e2a<code>ndim<\/code>\u5c5e\u6027\uff0c\u53ef\u4ee5\u8fd4\u56de\u6570\u7ec4\u7684\u7ef4\u6570\uff08\u5373\u8f74\u7684\u6570\u91cf\uff09\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a2D\u6570\u7ec4<\/strong><\/h2>\n<p>array_2d = np.array([[1, 2, 3], [4, 5, 6]])<\/p>\n<h2><strong>\u67e5\u770b\u6570\u7ec4\u7684\u7ef4\u6570<\/strong><\/h2>\n<p>print(array_2d.ndim)  # \u8f93\u51fa: 2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528<code>shape<\/code>\u5c5e\u6027<\/h4>\n<\/p>\n<p><p>NumPy\u6570\u7ec4\u7684<code>shape<\/code>\u5c5e\u6027\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u6570\u7ec4\u6bcf\u4e2a\u7ef4\u5ea6\u5927\u5c0f\u7684\u5143\u7ec4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a3D\u6570\u7ec4<\/strong><\/h2>\n<p>array_3d = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])<\/p>\n<h2><strong>\u67e5\u770b\u6570\u7ec4\u7684\u5f62\u72b6<\/strong><\/h2>\n<p>print(array_3d.shape)  # \u8f93\u51fa: (2, 2, 2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Pandas\u67e5\u770b\u6570\u636e\u7ef4\u5ea6<\/h3>\n<\/p>\n<p><p>Pandas\u662f\u4e00\u4e2a\u7528\u4e8e\u6570\u636e\u64cd\u4f5c\u548c\u5206\u6790\u7684\u5f3a\u5927\u5e93\uff0cDataFrame\u662fPandas\u4e2d\u7684\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u7528\u4e8e\u8868\u793a\u8868\u683c\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u67e5\u770bPandas DataFrame\u7ef4\u5ea6\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528<code>shape<\/code>\u5c5e\u6027<\/h4>\n<\/p>\n<p><p>Pandas DataFrame\u7684<code>shape<\/code>\u5c5e\u6027\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u884c\u6570\u548c\u5217\u6570\u7684\u5143\u7ec4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aDataFrame<\/strong><\/h2>\n<p>data = {&#39;A&#39;: [1, 2, 3], &#39;B&#39;: [4, 5, 6]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u67e5\u770bDataFrame\u7684\u5f62\u72b6<\/strong><\/h2>\n<p>print(df.shape)  # \u8f93\u51fa: (3, 2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528<code>ndim<\/code>\u5c5e\u6027<\/h4>\n<\/p>\n<p><p>Pandas DataFrame\u7684<code>ndim<\/code>\u5c5e\u6027\u8fd4\u56deDataFrame\u7684\u7ef4\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aDataFrame<\/strong><\/h2>\n<p>data = {&#39;A&#39;: [1, 2, 3], &#39;B&#39;: [4, 5, 6]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u67e5\u770bDataFrame\u7684\u7ef4\u6570<\/strong><\/h2>\n<p>print(df.ndim)  # \u8f93\u51fa: 2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528TensorFlow\u67e5\u770b\u6570\u636e\u7ef4\u5ea6<\/h3>\n<\/p>\n<p><p>TensorFlow\u662f\u4e00\u4e2a\u7528\u4e8e\u6df1\u5ea6\u5b66\u4e60\u7684\u5f00\u6e90\u6846\u67b6\uff0cTensor\u662fTensorFlow\u4e2d\u7684\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u7528\u4e8e\u8868\u793a\u591a\u7ef4\u6570\u7ec4\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u67e5\u770bTensorFlow Tensor\u7ef4\u5ea6\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528<code>shape<\/code>\u5c5e\u6027<\/h4>\n<\/p>\n<p><p>TensorFlow Tensor\u7684<code>shape<\/code>\u5c5e\u6027\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u6bcf\u4e2a\u7ef4\u5ea6\u5927\u5c0f\u7684\u5143\u7ec4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tensorflow as tf<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aTensor<\/strong><\/h2>\n<p>tensor = tf.constant([[1, 2, 3], [4, 5, 6]])<\/p>\n<h2><strong>\u67e5\u770bTensor\u7684\u5f62\u72b6<\/strong><\/h2>\n<p>print(tensor.shape)  # \u8f93\u51fa: (2, 3)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528<code>rank<\/code>\u65b9\u6cd5<\/h4>\n<\/p>\n<p><p>TensorFlow Tensor\u7684<code>rank<\/code>\u65b9\u6cd5\u8fd4\u56deTensor\u7684\u7ef4\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tensorflow as tf<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aTensor<\/strong><\/h2>\n<p>tensor = tf.constant([[1, 2, 3], [4, 5, 6]])<\/p>\n<h2><strong>\u67e5\u770bTensor\u7684\u7ef4\u6570<\/strong><\/h2>\n<p>print(tf.rank(tensor))  # \u8f93\u51fa: 2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528PyTorch\u67e5\u770b\u6570\u636e\u7ef4\u5ea6<\/h3>\n<\/p>\n<p><p>PyTorch\u662f\u53e6\u4e00\u4e2a\u7528\u4e8e\u6df1\u5ea6\u5b66\u4e60\u7684\u5f00\u6e90\u6846\u67b6\uff0cTensor\u662fPyTorch\u4e2d\u7684\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u7528\u4e8e\u8868\u793a\u591a\u7ef4\u6570\u7ec4\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u67e5\u770bPyTorch Tensor\u7ef4\u5ea6\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528<code>shape<\/code>\u5c5e\u6027<\/h4>\n<\/p>\n<p><p>PyTorch Tensor\u7684<code>shape<\/code>\u5c5e\u6027\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u6bcf\u4e2a\u7ef4\u5ea6\u5927\u5c0f\u7684\u5143\u7ec4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import torch<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aTensor<\/strong><\/h2>\n<p>tensor = torch.tensor([[1, 2, 3], [4, 5, 6]])<\/p>\n<h2><strong>\u67e5\u770bTensor\u7684\u5f62\u72b6<\/strong><\/h2>\n<p>print(tensor.shape)  # \u8f93\u51fa: torch.Size([2, 3])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528<code>dim<\/code>\u65b9\u6cd5<\/h4>\n<\/p>\n<p><p>PyTorch Tensor\u7684<code>dim<\/code>\u65b9\u6cd5\u8fd4\u56deTensor\u7684\u7ef4\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import torch<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aTensor<\/strong><\/h2>\n<p>tensor = torch.tensor([[1, 2, 3], [4, 5, 6]])<\/p>\n<h2><strong>\u67e5\u770bTensor\u7684\u7ef4\u6570<\/strong><\/h2>\n<p>print(tensor.dim())  # \u8f93\u51fa: 2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528\u5176\u4ed6\u65b9\u6cd5\u67e5\u770b\u6570\u636e\u7ef4\u5ea6<\/h3>\n<\/p>\n<p><h4>1. \u4f7f\u7528\u539f\u751fPython\u6570\u636e\u7ed3\u6784<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8ePython\u539f\u751f\u6570\u636e\u7ed3\u6784\uff08\u5982\u5217\u8868\u548c\u5143\u7ec4\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528\u9012\u5f52\u51fd\u6570\u6765\u8ba1\u7b97\u5176\u7ef4\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u4e00\u4e2a\u9012\u5f52\u51fd\u6570\u6765\u8ba1\u7b97\u7ef4\u6570<\/p>\n<p>def get_dimensions(data):<\/p>\n<p>    if isinstance(data, list):<\/p>\n<p>        return 1 + get_dimensions(data[0])<\/p>\n<p>    return 0<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u591a\u7ef4\u5217\u8868<\/strong><\/h2>\n<p>data = [[1, 2, 3], [4, 5, 6]]<\/p>\n<h2><strong>\u67e5\u770b\u5217\u8868\u7684\u7ef4\u6570<\/strong><\/h2>\n<p>print(get_dimensions(data))  # \u8f93\u51fa: 2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528scikit-learn\u5e93<\/h4>\n<\/p>\n<p><p>scikit-learn\u662f\u4e00\u4e2a\u7528\u4e8e<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u7684\u6d41\u884c\u5e93\uff0c\u867d\u7136\u5b83\u672c\u8eab\u6ca1\u6709\u4e13\u95e8\u7684\u65b9\u6cd5\u6765\u67e5\u770b\u6570\u636e\u7ef4\u5ea6\uff0c\u4f46\u4f60\u53ef\u4ee5\u4f7f\u7528NumPy\u6570\u7ec4\u6216Pandas DataFrame\u8fdb\u884c\u6570\u636e\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.datasets import load_iris<\/p>\n<p>import pandas as pd<\/p>\n<h2><strong>\u52a0\u8f7dIris\u6570\u636e\u96c6<\/strong><\/h2>\n<p>iris = load_iris()<\/p>\n<p>data = iris.data<\/p>\n<h2><strong>\u5c06\u6570\u636e\u8f6c\u6362\u4e3aDataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame(data, columns=iris.feature_names)<\/p>\n<h2><strong>\u67e5\u770bDataFrame\u7684\u5f62\u72b6<\/strong><\/h2>\n<p>print(df.shape)  # \u8f93\u51fa: (150, 4)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528\u5176\u4ed6\u9ad8\u9636\u5e93\u67e5\u770b\u6570\u636e\u7ef4\u5ea6<\/h3>\n<\/p>\n<p><h4>1. \u4f7f\u7528Dask\u5e93<\/h4>\n<\/p>\n<p><p>Dask\u662f\u4e00\u4e2a\u7528\u4e8e\u5e76\u884c\u8ba1\u7b97\u7684\u6570\u636e\u5904\u7406\u5e93\uff0cDask DataFrame\u662fDask\u4e2d\u7684\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u7528\u4e8e\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u67e5\u770bDask DataFrame\u7ef4\u5ea6\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import dask.dataframe as dd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aDask DataFrame<\/strong><\/h2>\n<p>data = {&#39;A&#39;: [1, 2, 3], &#39;B&#39;: [4, 5, 6]}<\/p>\n<p>ddf = dd.from_pandas(pd.DataFrame(data), npartitions=1)<\/p>\n<h2><strong>\u67e5\u770bDask DataFrame\u7684\u5f62\u72b6<\/strong><\/h2>\n<p>print(ddf.shape)  # \u8f93\u51fa: (3, 2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528Xarray\u5e93<\/h4>\n<\/p>\n<p><p>Xarray\u662f\u4e00\u4e2a\u7528\u4e8e\u5904\u7406\u591a\u7ef4\u6570\u7ec4\u7684\u5e93\uff0cDataset\u662fXarray\u4e2d\u7684\u4e00\u79cd\u6570\u636e\u7ed3\u6784\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u67e5\u770bXarray Dataset\u7ef4\u5ea6\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import xarray as xr<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aXarray Dataset<\/strong><\/h2>\n<p>data = xr.Dataset({&#39;A&#39;: ((&#39;x&#39;, &#39;y&#39;), [[1, 2, 3], [4, 5, 6]])})<\/p>\n<h2><strong>\u67e5\u770bDataset\u7684\u7ef4\u6570<\/strong><\/h2>\n<p>print(len(data.dims))  # \u8f93\u51fa: 2<\/p>\n<h2><strong>\u67e5\u770bDataset\u7684\u5f62\u72b6<\/strong><\/h2>\n<p>print(data.sizes)  # \u8f93\u51fa: Frozen({&#39;x&#39;: 2, &#39;y&#39;: 3})<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u4f7f\u7528\u5176\u4ed6\u673a\u5668\u5b66\u4e60\u6846\u67b6\u67e5\u770b\u6570\u636e\u7ef4\u5ea6<\/h3>\n<\/p>\n<p><h4>1. \u4f7f\u7528Keras\u67e5\u770b\u6570\u636e\u7ef4\u5ea6<\/h4>\n<\/p>\n<p><p>Keras\u662f\u4e00\u4e2a\u7528\u4e8e\u6df1\u5ea6\u5b66\u4e60\u7684\u9ad8\u5c42\u6846\u67b6\uff0cTensor\u662fKeras\u4e2d\u7684\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u7528\u4e8e\u8868\u793a\u591a\u7ef4\u6570\u7ec4\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u67e5\u770bKeras Tensor\u7ef4\u5ea6\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from keras import backend as K<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aNumPy\u6570\u7ec4<\/strong><\/h2>\n<p>array = np.array([[1, 2, 3], [4, 5, 6]])<\/p>\n<h2><strong>\u5c06NumPy\u6570\u7ec4\u8f6c\u6362\u4e3aKeras Tensor<\/strong><\/h2>\n<p>tensor = K.constant(array)<\/p>\n<h2><strong>\u67e5\u770bTensor\u7684\u5f62\u72b6<\/strong><\/h2>\n<p>print(K.int_shape(tensor))  # \u8f93\u51fa: (2, 3)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528MXNet\u67e5\u770b\u6570\u636e\u7ef4\u5ea6<\/h4>\n<\/p>\n<p><p>MXNet\u662f\u4e00\u4e2a\u7528\u4e8e\u6df1\u5ea6\u5b66\u4e60\u7684\u5f00\u6e90\u6846\u67b6\uff0cNDArray\u662fMXNet\u4e2d\u7684\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u7528\u4e8e\u8868\u793a\u591a\u7ef4\u6570\u7ec4\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u67e5\u770bMXNet NDArray\u7ef4\u5ea6\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import mxnet as mx<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aNDArray<\/strong><\/h2>\n<p>ndarray = mx.nd.array([[1, 2, 3], [4, 5, 6]])<\/p>\n<h2><strong>\u67e5\u770bNDArray\u7684\u5f62\u72b6<\/strong><\/h2>\n<p>print(ndarray.shape)  # \u8f93\u51fa: (2, 3)<\/p>\n<h2><strong>\u67e5\u770bNDArray\u7684\u7ef4\u6570<\/strong><\/h2>\n<p>print(len(ndarray.shape))  # \u8f93\u51fa: 2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516b\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u4ecb\u7ecd\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0cPython\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u5f0f\u6765\u67e5\u770b\u6570\u636e\u7684\u7ef4\u5ea6\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u4f60\u6240\u4f7f\u7528\u7684\u6570\u636e\u7c7b\u578b\u548c\u5e93\u3002<strong>NumPy\u3001Pandas\u3001TensorFlow\u3001PyTorch\u3001\u4ee5\u53ca\u5176\u4ed6\u9ad8\u9636\u5e93\u5982Dask\u548cXarray\uff0c\u90fd\u63d0\u4f9b\u4e86\u4fbf\u6377\u7684\u65b9\u6cd5\u6765\u67e5\u770b\u6570\u636e\u7684\u7ef4\u5ea6<\/strong>\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u7406\u89e3\u548c\u5904\u7406\u6570\u636e\uff0c\u4ece\u800c\u5728\u6570\u636e\u5206\u6790\u548c\u673a\u5668\u5b66\u4e60\u4efb\u52a1\u4e2d\u53d6\u5f97\u66f4\u597d\u7684\u6548\u679c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u67e5\u770b\u6570\u636e\u7684\u7ef4\u5ea6\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u67e5\u770b\u6570\u636e\u7684\u7ef4\u5ea6\u901a\u5e38\u53d6\u51b3\u4e8e\u6570\u636e\u7684\u7c7b\u578b\u3002\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662fNumPy\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528<code>.shape<\/code>\u5c5e\u6027\u83b7\u53d6\u7ef4\u5ea6\u4fe1\u606f\uff1b\u5982\u679c\u662fPandas DataFrame\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528<code>.shape<\/code>\u6216<code>.info()<\/code>\u65b9\u6cd5\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5c06\u8fd4\u56de\u6570\u636e\u7684\u884c\u6570\u548c\u5217\u6570\uff0c\u5e2e\u52a9\u60a8\u4e86\u89e3\u6570\u636e\u7684\u7ed3\u6784\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u67e5\u770b\u4e0d\u540c\u7c7b\u578b\u6570\u636e\u7684\u7ef4\u5ea6\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/strong><br \/>\u5bf9\u4e8eNumPy\u6570\u7ec4\uff0c\u4f7f\u7528<code>.ndim<\/code>\u5c5e\u6027\u53ef\u4ee5\u83b7\u53d6\u7ef4\u5ea6\u7684\u6570\u91cf\uff0c\u800c<code>.shape<\/code>\u5219\u8fd4\u56de\u4e00\u4e2a\u5143\u7ec4\uff0c\u663e\u793a\u6bcf\u4e2a\u7ef4\u5ea6\u7684\u5927\u5c0f\u3002\u5bf9\u4e8ePandas DataFrame\uff0c<code>.info()<\/code>\u65b9\u6cd5\u4e0d\u4ec5\u663e\u793a\u7ef4\u5ea6\u4fe1\u606f\uff0c\u8fd8\u63d0\u4f9b\u6570\u636e\u7c7b\u578b\u548c\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u7684\u6982\u89c8\uff0c\u8fd9\u5bf9\u5206\u6790\u6570\u636e\u975e\u5e38\u6709\u5e2e\u52a9\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u6570\u636e\u7ef4\u5ea6\u4e0d\u5339\u914d\u7684\u95ee\u9898\uff1f<\/strong><br \/>\u5728\u6570\u636e\u5206\u6790\u4e2d\uff0c\u7ef4\u5ea6\u4e0d\u5339\u914d\u53ef\u80fd\u5bfc\u81f4\u9519\u8bef\u6216\u4e0d\u51c6\u786e\u7684\u7ed3\u679c\u3002\u89e3\u51b3\u6b64\u7c7b\u95ee\u9898\u7684\u5e38\u7528\u65b9\u6cd5\u5305\u62ec\uff1a\u68c0\u67e5\u6570\u636e\u6e90\uff0c\u786e\u4fdd\u6570\u636e\u7684\u683c\u5f0f\u548c\u7ed3\u6784\u4e00\u81f4\uff1b\u4f7f\u7528Pandas\u7684<code>merge()<\/code>\u6216<code>concat()<\/code>\u51fd\u6570\u65f6\uff0c\u4ed4\u7ec6\u5339\u914d\u5408\u5e76\u6761\u4ef6\uff1b\u4e5f\u53ef\u4ee5\u4f7f\u7528NumPy\u7684<code>reshape()<\/code>\u51fd\u6570\u8c03\u6574\u6570\u7ec4\u7684\u7ef4\u5ea6\uff0c\u4ee5\u786e\u4fdd\u6570\u636e\u7684\u4e00\u81f4\u6027\u548c\u53ef\u64cd\u4f5c\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u67e5\u770bPython\u4e2d\u6570\u636e\u7684\u7ef4\u5ea6\uff0c\u53ef\u4ee5\u4f7f\u7528\u51e0\u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u6570\u636e\u7684\u7c7b\u578b\u3002\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u7684ndim\u5c5e [&hellip;]","protected":false},"author":3,"featured_media":1154203,"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\/1154196"}],"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=1154196"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1154196\/revisions"}],"predecessor-version":[{"id":1154204,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1154196\/revisions\/1154204"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1154203"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1154196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1154196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1154196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}