本文实例总结了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
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?