numpy数组的属性
impot numpy as np
myarray = np.array([[1, 2, 3]
4, 5, 6]], dtype=np.int)
print("维度:", myarray.ndim)
print("形状:", myarray.shape)
print("元素总数:", myarray.size)
print("数据类型:", myarray.dtype)
数组的创建
- 用具体的列表来创建
myarray = np.array([[1, 2, 3]
4, 5, 6]], dtype=np.int)
- 用zeros、ones、empty函数创建数组
zeros_array = np.zeros((4,3), dtype=np.int)
ones_array = np.ones((4,3), dtype=np.int)
empty_array = np.empty((4,3), dtype=np.float)
- 用区间来生成
arange_array = np.arange(0, 12, 1).reshape((4,3))
linspace_array = np.linspace(0, 12, 12).reshape((4,3))
基本运算
a = np.linspace(0, 4, 4).reshape((2,2))
b = np.arange(5, 9, 1).reshape((2, 2))
sum = a + b
the_sin = np.sin(a)
dot = np.dot(a, b)
the_max = np.max(a)
the_axis_max = np.max(a, axis=0)
a = np.clip(a, 0, 10)
a = np.transpose(a)