# convert List to Numpy array
import numpy as np
L1 = [1,2,3,4]
L2 = ["H", "E", "N","s"]
L3 = [3,4,5,6]
N = np.array([L1,L2,L3])
print(N)
print(type(N))
# convert tuple to Numpy array
T1 = (1,2,3,4)
T2 = (4,5,6,7)
N = np.array((T1,T2))
print(N)
# convert set to Numpy array
S1 = {1,2,3}
S2 = {4,5,6}
N = np.array((S1,S2))
print(N)
# convert dic to Numpy array
D = {"inas":1, "hyder":2, "yusuf":3, "mariam":4}
N = np.array(D)
print(N,type(N))
# 0-D called scalar array which is contained one variable, where array conatins variables.
D = [1]
N = np.array(D)
print(N, type(N))
# 1-D
D = [1,2,3,4]
N = np.array(D)
print(N, type(N))
# 2-D
L1 = [1,2,3,4]
L2 = ["H", "E", "N","s"]
N = np.array([L1,L2])
print(N, "The dim of array is:",N.ndim) #2 D rows = 2
# 3-D
L1 = [1,2,3,4]
L2 = ["H", "E", "N","s"]
L3 = ["H", "E", "N","s"]
N = np.array([[L1],[L2]])
print(N, "The dim of array is:",N.ndim) #3 D rows = 3
# 4-D
L1 = [1,2,3,4]
L2 = ["H", "E", "N","s"]
L3 = ["H", "E", "N","s"]
N = np.array([[[L1],[L2]]])
print(N, "The dim of array is:",N.ndim) #3 D rows = 4
# 5-D
L1 = [1,2,3,4]
L2 = ["H", "E", "N","s"]
L3 = ["H", "E", "N","s"]
N = np.array([[[[L1]]]])
print(N, "The dim of array is:",N.ndim) #5 D rows = 5
L1 = [[1,2,3]]N = np.array(L1,ndmin=5)
print(N, "The dim of array is:",N.ndim) #5 D rows = 5
- Blogger Comment
- Facebook Comment
Subscribe to:
Post Comments
(
Atom
)
0 Comments:
Post a Comment