Constructing one dimensional array :
- ndarray() is pre-defined in numpy
- it is used to construct array object
- We need to specify the shape of array and type of array in the construction.
- When we don’t specify the type of data in array construction, by default the elements are float type.
import numpy as np
arr = np.ndarray(shape=(5))
print("Size :",arr.size)
print("Datatype :",arr.dtype)
We can specify the type in the construction of Array:
import numpy as np
arr = np.ndarray(shape=(5),dtype=int)
print("Size :",arr.size)
print("Datatype :",arr.dtype)
Read size of array and construct:
- When we don’t specify the size, it is by default float type.
- Once array has been constructed, all elements are default values.
import numpy as np
n = int(input("Enter size :"))
arr = np.ndarray(shape=(n),dtype=int)
print("Elements are :")
for ele in arr:
print(ele)