您当前的位置: 首页 >  Python

嗨学编程

暂无认证

  • 0浏览

    0关注

    1405博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Python中numpy模块常见用法demo实例小结

嗨学编程 发布时间:2019-04-17 15:06:15 ,浏览量:0

本文实例总结了Python中numpy模块常见用法。分享给大家供大家参考,具体如下:

'''
想要学习Python?Python学习交流群:973783996满足你的需求,资料都已经上传群文件,可以自行下载!
'''
import numpy as np
arr = np.array([[1,2,3], [2,3,4]])
print(arr)
print(type(arr))
print('number of dim:', arr.ndim)
print('shape:', arr.shape)
print('size:', arr.size)

[[1 2 3]  [2 3 4]] number of dim: 2 shape: (2, 3) size: 6

a32 = np.array([1,23,456], dtype=np.int)
print(a32.dtype)
a64 = np.array([1,23,456], dtype=np.int64)
print(a64.dtype)
f64 = np.array([1,23,456], dtype=np.float)
print(f64.dtype)

int32 int64 float64

z = np.zeros((3, 4))
print(z)
print(z.dtype)
print()
one = np.ones((3, 4), dtype=int)
print(one)
print(one.dtype)
print()
emt = np.empty((3, 4), dtype=int)
print(emt)
print(emt.dtype)
print()
ran = np.arange(12).reshape((3,4))
print(ran)
print(ran.dtype)
print()
li = np.linspace(1, 10, 6).reshape(2, 3)
print(li)
print(li.dtype)

[[0. 0. 0. 0.]  [0. 0. 0. 0.]  [0. 0. 0. 0.]] float64 [[1 1 1 1]  [1 1 1 1]  [1 1 1 1]] int32 [[          0  1072693248  1717986918  1074161254]  [ 1717986918  1074947686 -1717986918  1075419545]  [ 1717986918  1075865190           0  1076101120]] int32 [[ 0  1  2  3]  [ 4  5  6  7]  [ 8  9 10 11]] int32 [[ 1.   2.8  4.6]  [ 6.4  8.2 10. ]] float64

a = np.array([10,20,30,40])
b = np.arange(4)
print(a)
print(b)
print()
print(a+b)
print(a-b)
print(a*b)
print()
print(a**b)
print()
print(10*np.sin(a))
print()
print(b            
关注
打赏
1663681728
查看更多评论
0.0931s