numpy tutorial
numpy常用函数
np.arange(n): 元素从0到n-1的ndarray类型
np.ones(shape): 生成全1
np.zeros((shape), ddtype = np.int32) : 生成int32型的全0
np.full(shape, val): 生成全为val
np.eye(n) : 生成单位矩阵
np.ones_like(a) : 按数组a的形状生成全1的数组
np.zeros_like(a): 同理
np.full_like (a, val) : 同理
np.linspace(1,10,4): 根据起止数据等间距地生成数组
np.linspace(1,10,4, endpoint = False): endpoint 表示10是否作为生成的元素
numpy.full(shape, fill_value, dtype=None, order=’C’)
shape:矩阵的纬度
fill_value:填充值
创建一个由常数填充的数组,第一个参数是数组的形状,第二个参数是数组中填充的常数。
import numpy as np
a = np.full((2, 2), np.inf)
b = np.full((2, 2), 10)
print(a)
print(b)
result
[[ inf inf]
[ inf inf]]
[[10 10]
[10 10]]
numpy.eye(n): 创建单位矩阵,函数中的参数n,则创建n * n的单位矩阵
np.eye(