numpy 一维4向量的shape只有元组的第一个元有数字

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')])
 
————————————————
版权声明:本文为优快云博主「天行_」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/lens___/article/details/83927880

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值