Numpy是基于矩阵的计算,例如一个2行3列的矩阵: [[1,2,3], [2,3,4]]
它在python中是列表形式,在numpy中需要将列表转换成numpy可识别的矩阵。
# 命名为数组,将列表转化为矩阵
import numpy as np
array = np.array([[1,2,3],[2,3,4]])
print(array)
[[1 2 3]
[2 3 4]]
查看Numpy中数组的基本属性
1. ndim:查看数组是几维
print('number of dim:',array.ndim)
number of dim: 2
2. shape:查看数组的形状:几行几列
print('shape:',array.shape)
shape: (2, 3)
3. size:查看数组中总共有多少个元素
print('size:',array.size)
size: 6