#Working with 1-Dimension arrayimport numpy as npL = [1,2,3,4,5]N = np.array(L)print(N.ndim)print(N.shape)print(N[0]+N[4]) # 1 + 4 print(N[0])print(N[1])print(N[-1])print(N>3)print(N[N>3])# convert bool to valueodd = N[N%2==1] # print the odd value print(odd)#Working with 2-Dimension arrayimport numpy as npL = [[1,2,3,4,5]]N = np.array(L)print(N.ndim)print(N.shape)print(N[0,0]+N[0,1]) # 1 + 4 print(N[0,0])# 0 represent row, 0 represent column, so in row we can not wrote more than 0 coz it just one row print(N[0,4])# in column we can not wrote more than 4 coze it just 5 column#Working with 3-Dimension arrayimport numpy as npL = [[[1,2,3,4,5]]]N = np.array(L)print(N.ndim)print(N.shape)print(N[0,0,0]+N[0,0,1]) # 1 + 4 print(N[0,0,0])# 0 represent row, 0 represent column, so in row we can not wrote more than 0 coz it just one row print(N[0,0,4])# in column we can not wrote more than 4 coze it just 5 columnL1 = [1,2,3,4]L2 = [6,7,8,9]arr = np.array([L1,L2])print(arr)print(arr[1,2])print(arr.ndim)print(arr.shape)# 2,4 two row, 4 columnN = np.array([[[1,2,3]]])print(N[0,0,1])N = np.array([[[1,2,3],[4,5,6]]])print(N)print(N[0,1,2])print(N[0,1,-1]) #print the last element of array
0 Comments:
Post a Comment