本文实例总结了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
关注
打赏
热门博文
- Python:用tkinter制做一个音乐下载小软件
- Python丨小学妹喜欢看漫画,于是我写了四十行代码获取了它所有漫画
- 女同桌找我要表情包,还好我会Python,分分钟给她下载几十个G...
- 为了防止这上面的文章被封,我连夜用Python获取了它所有内容,真香~
- 这个Python读取文件的方法,堪称天花板级别...
- Python做一个通过输入bv号就能下载视频的工具,评论和弹幕也不放过
- Python:50行代码实现下载小说,图片章节可自动识别转文字保存...
- 只用二十行代码,用Python实现获取网抑云榜单文件保存本地,非常简单...
- 发现一个舔狗神器,Python真的太厉害了,自动下载妹子视频...
- 使用Python探索四大名著【红楼梦】人物之间的关系,简直帅呆了