时间:2021-05-22
本文实例总结了Python中numpy模块常见用法。分享给大家供大家参考,具体如下:
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
int32
int64
float64
[[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
[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]
[[1 2]
[3 4]]
[[0 1]
[2 3]]
[[ 0 2]
[ 6 12]]
[[ 4 7]
[ 8 15]]
[[ 4 7]
[ 8 15]]
[[0.04456704 0.99481679 0.96599561 0.48590905]
[0.56512852 0.62887714 0.78829115 0.32759434]]
4.8011796551183945
0.04456704487406293
0.9948167913629338
[2.4912885 2.30989116]
[0.04456704 0.62887714 0.78829115 0.32759434]
[0.62282212 0.57747279]
[[ 2 3 4 5]
[ 6 7 8 9]
[10 11 12 13]]
0
11
7.5
7.5
[ 2 5 9 14 20 27 35 44 54 65 77 90]
[[1 1 1]
[1 1 1]
[1 1 1]]
(array([0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2], dtype=int32), array([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3], dtype=int32))
[[1 0]
[0 3]]
(array([0, 1], dtype=int32), array([0, 1], dtype=int32))
[[0 1]
[0 3]]
[[0 0]
[1 3]]
(array([0, 1], dtype=int32), array([1, 1], dtype=int32))
[[14 13 12 11]
[10 9 8 7]
[ 6 5 4 3]]
[[14 10 6]
[13 9 5]
[12 8 4]
[11 7 3]]
[[332 302 272 242]
[302 275 248 221]
[272 248 224 200]
[242 221 200 179]]
[[9 9 9 9]
[9 9 8 7]
[6 5 5 5]]
[3 4 5 6]
5
[[ 3 4 5 6]
[ 7 8 9 10]
[11 12 13 14]]
[11 12 13 14]
12
12
[13 14]
[[ 9 10]
[13 14]]
[3 4 5 6]
[ 7 8 9 10]
[11 12 13 14]
[ 3 7 11]
[ 4 8 12]
[ 5 9 13]
[ 6 10 14]
[ 3 4 5 6 7 8 9 10 11 12 13 14]
3
4
5
6
7
8
9
10
11
12
13
14
[[1 1 1]
[2 2 2]
[1 1 1]
[2 2 2]]
(3,) (3,)
(4, 3)
[1 1 1 2 2 2]
[[1 1 1]]
[[1]
[1]
[1]]
[[1 2]
[1 2]
[1 2]]
[[1 1 1]
[2 2 2]]
[[1 2]
[1 2]
[1 2]]
[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
[array([[0, 1],
[4, 5],
[8, 9]]), array([[ 2, 3],
[ 6, 7],
[10, 11]])]
[array([[0, 1, 2, 3]]), array([[4, 5, 6, 7]]), array([[ 8, 9, 10, 11]])]
[array([[0, 1],
[4, 5],
[8, 9]]), array([[ 2],
[ 6],
[10]]), array([[ 3],
[ 7],
[11]])]
[array([[0, 1],
[4, 5],
[8, 9]]), array([[ 2, 3],
[ 6, 7],
[10, 11]])]
[array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])]
[0 1 2 3] [0 1 2 3] [0 1 2 3] [0 1 2 3]
[5 1 2 3] [5 1 2 3] [5 1 2 3] [0 1 2 3]
172730832 172730832 172730832 172730792
更多关于Python相关内容感兴趣的读者可查看本站专题:《Python数学运算技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》
希望本文所述对大家Python程序设计有所帮助。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了Python模块、包(Package)概念与用法。分享给大家供大家参考,具体如下:Python中”模块”的概念在开发中,我们会有很多函数,我们可以
本文实例讲述了Python中sys模块功能与用法。分享给大家供大家参考,具体如下:
本文实例讲述了python中asyncore模块的用法,分享给大家供大家参考。具体方法如下:实例代码如下:##asyncoreimportasyncore,so
本文实例讲述了python中随机函数random用法。分享给大家供大家参考。具体如下:python中的random模块功能非常强大,可以生成各种随机值#!pyt
本文实例讲述了Python科学计算包numpy用法。分享给大家供大家参考,具体如下:1数据结构numpy使用一种称为ndarray的类似Matlab的矩阵式数据