- numpy.zeros(shape, dtype=float, order='c')创建指定大小的数组,数组元素以 0 来填充
- numpy.ones() 创建一个全是1的数组
- numpy.empty() 创建一个内容随机并且依赖于内存状态的数组
#如不指定类型,默认创建的数组类型为float64
- numpy.random.permutation(x) x为序列或整数,当x为整数时,返回随机排列range(x);当x为序列时,返回x随机排列的序列
- numpy.array(object, dtype=None, copy=True, order='K', subok=False, ndmin=0) 将对象转换为数组
- tolist() 将数组转换为列表
- arange([start, ]stop, [step, ]dtype=None) 返回的是array类型 默认从零开始,步长为1
- numpy.linspce(start, stop, num=50, endpoint=True, retstep=False, dtype=None) 返回固定个数的步长相同的数据
- 矩阵的乘法运算符*是按元素位置计算,矩阵乘法可以使用dot函数实现
-
numpy.fromfunction
(function, shape, *, dtype=<class 'float'>, **kwargs) -
functioncallable
The function is called with N parameters, where N is the rank of
shape
. Each parameter represents the coordinates of the array varying along a specific axis. For example, ifshape
were(2, 2)
, then the parameters would bearray([[0, 0], [1, 1]])
andarray([[0, 1], [0, 1]])
[In]:def fun(x, y):
return x * 2 + y
b = np.fromfunction(fun,(2, 3),dtype=int)
[In]:b
[Out]:array([[0, 1, 2],
[2, 3, 4]])
- 组合拆分数组
- numpy.vstack() 使多个数组沿第一个轴组合
- numpy.hstack() 沿第二个轴组合
- numpy.column_stack() 将多个一维数组按对应位置组合成新的二维数组
- numpy.vsplit() 将数组沿纵轴分割
- numpy.hsplit() 将数组沿水平轴分割