1.打开python,下载numby包
编写代码
import numpy as np #给函数取别名方便调用
a = np.array([1,2,3])
print (a)
#输出结果如下:[1 2 3]
# 多于一个维度
a = np.array([[1, 2], [3, 4]])
print (a)
#输出结果如下:
# [[1 2]
# [3 4]]
# 最小维度
a = np.array([1, 2, 3, 4, 5], ndmin = 2)
print (a)
#输出如下:[[1 2 3 4 5]]
# dtype 参数
a = np.array([1, 2, 3], dtype = complex)
print (a)
#输出结果如下:[1.+0.j 2.+0.j 3.+0.j]
import numpy as np
a = np.arange(6).reshape(2,3)
print ('原始数组是:')
print (a) print ('\n')
print ('迭代输出元素:')
for x in np.nditer(a):
print (x, end=", " )
print ('\n')
import numpy as np
a = np.arange(0,60,5)
a = a.reshape(3,4)
print ('原始数组是:')
print (a)
print ('\n')
print ('原始数组的转置是:')
b = a.T
print (b)
print ('\n')
print ('以 C 风格顺序排序:')
c = b.copy(order='C')
print (c)
for x in np.nditer(c):
print (x, end=", " )
print ('\n')
print ('以 F 风格顺序排序:')
c = b.copy(order='F')
print (c)
for x in np.nditer(c):
print (x, end=", " )
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)