【model01】numpy

import numpy as np

array = np.array([[1,2,3],
                  [2,3,4]])
print(array)
print('number of dim:',array.ndim)#维数
print('shape:',array.shape)
print('size:',array.size)#总共元素的多少
[[1 2 3]
 [2 3 4]]
number of dim: 2
shape: (2, 3)
size: 6
import numpy as np
a = np.array([[2,23,4],
              [7,58,3]],dtype=np.float32)#定义数据类型
print(a)
print(a.dtype,'\n')

b = np.zeros((3,4))#零矩阵
print(b,'\n')

c = np.ones((3,4),dtype=np.int16)
print(c,'\n')

d = np.empty((3,4))#空矩阵
print(d,'\n')
[[ 2. 23.  4.]
 [ 7. 58.  3.]]
float32 

[[0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]] 

[[1 1 1 1]
 [1 1 1 1]
 [1 1 1 1]] 

[[0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]] 
import numpy as np

a = np.arange(10,20,2)#定义间隔
print(a,'\n')

b = np.arange(12).reshape((3,4))#reshape成指定格式矩阵
print(b,'\n')

c = np.linspace(1,10,20).reshape((5,4))#定义段数,自动分段
print(c,'\n')
[10 12 14 16 18] 

[[ 0  1  2  3]
 [ 4  5  6  7]
 [ 8  9 10 11]] 

[[ 1.          1.47368421  1.94736842  2.42105263]
 [ 2.89473684  3.36842105  3.84210526  4.31578947]
 [ 4.78947368  5.26315789  5.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值