import numpy as np
example=np.arange(24).reshape(3,4,2)
print(example)----------------------------------------->[[[ 0 1]
[ 2 3]
[ 4 5]
[ 6 7]]
[[ 8 9]
[10 11]
[12 13]
[14 15]]
[[16 17]
[18 19]
[20 21]
[22 23]]]
1.->ndim数组的维度
print("维度:",example.ndim)---------------------------->维度: 3
2.->sie数组元素的个数
print("01-元素个数:",example.size)--------------------->01-元素个数: 24
3.->itemsize数组中每个元素所占字节数
print("每个元素所占字节数:",example.itemsize)------------>每个元素所占字节数: 4
4.->nbytes整个数组所占字节数
print("数组所占字节数:",example.nbytes)---------------->
print("数组所占字节数:",example.size*example.itemsize)->数组所占字节数: 96
5.->T数组的转置结果
print(example.T)-------------------------------------->[[[ 0 8 16]
[ 2 10 18]
[ 4 12 20]
[ 6 14 22]]
[[ 1 9 17]
[ 3 11 19]
[ 5 13 21]
[ 7 15 23]]]
6.->real复数数组的实部
comp=np.array([2+5j,6+3j,4+2j])
print(comp)------------------------------------------->[2.+5.j 6.+3.j 4.+2.j]
real=comp.real
print("复数数组实部:\n",real)-------------------------->复数数组实部:[2. 6. 4.]
7.->imag复数数组的虚部
imag=comp.imag
print("复数数组虚部:\n",imag)-------------------------->复数数组虚部:[5. 3. 2.]
8.求comp复数数组的每个元素的模
interator=np.arange(9).reshape(3,3)
print(interator)--------------------------------------->[[0 1 2]
[3 4 5]
[6 7 8]]
print(np.sqrt(real**2+imag**2))------------------------>[5.38516481 6.70820393 4.47213595]
9.将数组展平成扁平迭代器
“`
result=interator.flat
for item in result:
print(item)————————————————————————->
0
1
2
3
4
5
6
7
8
“`