导入

import numpy as np

生成NumPy数组

x = np.array([1.0, 2.0, 3.0])
>>> print(x)
[ 1. 2. 3.]

shape/dtype

A = np.array([[1, 2], [3, 4]])
>>> print(A)
[[1 2]
[3 4]]
>>> A.shape
(2, 2)
返回数组的维度,几行几列。
>>> A.dtype
dtype(‘int64’)
返回数组类型

np.ndim(B)

np.ndim(B)
2
返回数组的维度