2019-01-15 创建二维数组
2019-01-15 本文已影响5人
七月那个阿瓜呀
1. 二维数组
1创建二维数组M*N维
myList = [([0] * N) for i in range(M)]
2. 取值
import numpy as np
Ni = np.array([([0] * 50) for i in range(80)])
print(Ni[0,1])
3. 每一个元素求平方
import numpy as np
from numpy.matlib import repmat
zhen1=np.array([[1,2,3,4],[5,6,7,8]])
#zhen=np.array([[1,1,1,1]])
zhen2= [[zhen1[i][j]**2 for j in range(len(zhen1[i]))] for i in range(len(zhen1))]
print(zhen2,np.shape(zhen2),type(zhen2),type(zhen2[0]),type(zhen2[0][0]))