importarray#initializingarraywitharrayvalues#initializesarraywithsignedintegersarr=array.array('i',[1,2,3])print("The new created array is : ",end="")foriinrange(0,3):print(arr[i],end=" ")print("\r")arr
Thenewcreatedarrayis:123array('i',[1,2,3])
numpy empty方法
importnumpyasnp#randomvaluesb=np.empty(2,dtype=int)print("Matrix b : \n",b)a=np.empty([2,2],dtype=int)print("\nMatrix a : \n",a)c=np.empty([3,3])print("\nMatrix c : \n",c)
importnumpyasgeekb=np.zeros(2,dtype=int)print("Matrix b : \n",b)a=np.zeros([2,2],dtype=int)print("\nMatrix a : \n",a)c=np.zeros([3,3])print("\nMatrix c : \n",c)