import numpy as np
X=np.array([[-0.60116],
[-0.94159],
[-0.74565],
[0.89583]])
w = [0]
b=1
z= np.matmul(X,w) + b
print(X.shape)
W = np.zeros(X.shape[1])
print("W=",W)
print("W.TYPE=",type(W),"w.shape=",W.shape)
W2 = np.zeros(X.shape[0])
print("W2=",W2)
print("W2.TYPE=",type(W2),"w2.shape=",W2.shape)
W3=np.array([[0, 0, 0, 0]])
print("W3=",W3)
print("W3.TYPE=",type(W3),"w3.shape=",W3.shape)
W4 = np.zeros(4)
print("W4=",W4)
print("W4.TYPE=",type(W4),"w4.shape=",W4.shape)
W5 = np.array([[0,0,0,0]])
print("W5=",W5)
print("W5.TYPE=",type(W5),"w5.shape=",W5.shape)
W6 = np.array([0,0,0,0])
print("W6=",W6)
print("W6.TYPE=",type(W6),"w6.shape=",W6.shape)
#result
(4, 1)
W= [0.]
W.TYPE= <class 'numpy.ndarray'> w.shape= (1,)
W2= [0. 0. 0. 0.]
W2.TYPE= <class 'numpy.ndarray'> w2.shape= (4,)
W3= [[0 0 0 0]]
W3.TYPE= <class 'numpy.ndarray'> w3.shape= (1, 4)
W4= [0. 0. 0. 0.]
W4.TYPE= <class 'numpy.ndarray'> w4.shape= (4,)
W5= [[0 0 0 0]]
W5.TYPE= <class 'numpy.ndarray'> w5.shape= (1, 4)
W6= [0 0 0 0]
W6.TYPE= <class 'numpy.ndarray'> w6.shape= (4,)
python numpy.zeros()函数的用法
原创天行_ 最后发布于2018-11-10 12:12:26 阅读数 9602 收藏
展开
numpy.zeros(shape,dtype=float,order = 'C')
返回给定形状和类型的新数组,用0填充。
参数:
shape:int 或 int 的元组
新阵列的形状,例如:(2,3)或2。
dtype:数据类型,可选
数组的所需数据类型,例如numpy.int8。默认是numpy.float64
order:{'C','F'},可选,默认:'C'
是否在内容中以行(C)或列(F)顺序存储多维数据。
返回: out:ndarray
具有给定形状,类型和顺序的0的数组。
Example:
np.zeros(5)
Out[1]: array([ 0., 0., 0., 0., 0.])
np.zeros((4,),dtype = int)
Out[2]: array([0, 0, 0, 0])
np.zeros((2,3))
Out[2]:
array([[ 0., 0., 0.],
[ 0., 0., 0.]])
s = (3,3)
np.zeros(s)
Out[3]:
array([[ 0., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.]])
np.zeros((2,),dtype = [('x','i4'),('y','i4')])
Out[4]:
array([(0, 0), (0, 0)],
dtype=[('x', '<i4'), ('y', '<i4')])
np.zeros((3,),dtype = [('x','i4'),('y','i4')])
Out[5]:
array([(0, 0), (0, 0), (0, 0)],
dtype=[('x', '<i4'), ('y', '<i4')])
————————————————
版权声明:本文为CSDN博主「天行_」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lens___/article/details/83927880