博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python中numpy模块常见用法demo实例小结
阅读量:2069 次
发布时间:2019-04-29

本文共 1456 字,大约阅读时间需要 4 分钟。

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

'''想要学习Python?Python学习交流群:973783996满足你的需求,资料都已经上传群文件,可以自行下载!'''import numpy as nparr = 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<3)print()

[10 20 30 40]

[0 1 2 3]
[10 21 32 43]
[10 19 28 37]
[  0  20  60 120]
[    1    20   900 64000]
[-5.44021111  9.12945251 -9.88031624  7.4511316 ]
[ True  True  True False]

 

转载地址:http://usnmf.baihongyu.com/

你可能感兴趣的文章
计算机英语编程中一些单词
查看>>
JavaScript 经典例子
查看>>
判断数据的JS代码
查看>>
js按键事件说明
查看>>
AJAX 初次体验!推荐刚学看这个满好的!
查看>>
AJAX 设计制作 在公司弄的 非得要做出这个养的 真晕!
查看>>
AJAX 自己研究玩的
查看>>
javascript(js)数组操作
查看>>
用JavaScript脚本实现Web页面信息交互
查看>>
window 窗口对象操作
查看>>
公司一位老员工愤然离去的留信!崩溃!
查看>>
C#技巧:网页表单自动填写技术(以gmail为例)
查看>>
C#基础概念二十五问
查看>>
C#在Excel中将连续多列相同数据项合并
查看>>
C#如何把html中的相对路径变成绝对路径
查看>>
用C#编写发手机中文短信息Windows服务
查看>>
C#的四个基本技巧
查看>>
编程实例 使用C#的BitmapData
查看>>
区分Oracle和SQL Server常用函数调用方法
查看>>
详解Visual C#数据库基本编程
查看>>