标签:单位 .sh size numpy nbsp 组成 array rand and
倒入numpy模块
import numpy as np
Array(数组)
a = np.array([1,2,3])
#a
#array([1,2,3])
type(a)
#nympy.ndarray
a.shape
#(3,) #一纬数据 看大小
a= a.reshape((1,-1) ) #明确行列,-1=3
a.shape
#(1,3) #1行3列
a = np.array([1,2,3,4,5,6]) a.shape #(6,) a= a.reshape((2,-1)) a.shape #(2,3) a #array( [[1,2,3], []4,5,6] ] )
###
a= a.reshape((-1,2))
a
array([
[1,2],
[3,4],
[5,6]
])
##取5
a[2,0]
## 将5换成55
a[2,0]= 55
zeros
a = zeros((3,3))
a
array([
[0.,0.,0.],
[0.,0.,0.],
[0.,0.,0.],
])
ones
a = np.ones((2,3)) a ## array([ [1.,1.,1.], [1.,1.,1.], ])
full
a = np.full((3,3),0) #3行3列,所有数据都是0
a = np.full((2,3),1) #2行3列,所有数据都是1
eye :单位矩阵
a = np.eye((3)) #左上右下为1,3行3列 array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])
random.random:创建随机数组,取值在0--1之间
a=np.random.random((3,4)) #3行4列,0-1之间数字组成的 array([[0.31970217, 0.52454361, 0.93528294, 0.59955502], [0.47355245, 0.7775892 , 0.8112688 , 0.58033926], [0.20438656, 0.37185309, 0.89225405, 0.61406772]])
数组:numpy.shape 与numpy.reshape函数
标签:单位 .sh size numpy nbsp 组成 array rand and
原文地址:https://www.cnblogs.com/catherine007/p/8946972.html