NumPy - 1
import numpy as np
mylist = list([1,2,3,4])
mylist
myarray = np.array([1,2,3,4])
myarray
new = myarray/2
new
new_list = mylist/2
type(myarray)
type(mylist)
# Creating an array
import numpy as np
myarray = np.array([1,2,3,4,5,6])
print(myarray)
type(myarray)
# 0-Dimensional array
myarray0 = np.array(40)
print(myarray0)
type(myarray0)
# 1- Dimension array
myarray1 = np.array([1,2,3])
print(myarray1)
# 2- Dimension array
myarray2 = np.array([[1,2,3],[4,5,6],[7,8,9]])
print(myarray2)
# 3- Dimensional array
myarray3 = np.array([[[1,2],[4,5]],[[1,2],[2,5]]])
print(myarray3)
type(myarray3)
# Dimension of arrays
print(myarray3.ndim)
print(myarray2.ndim)
print(myarray1.ndim)
print(myarray0.ndim)
# Higher dimension
myarray = np.array([1,2,3,4,5],ndmin=5)
print(myarray)
## Accessing the elements
print(myarray1)
myarray1[1]
print(myarray2)
print(myarray2[2, 1])
print(myarray1[-1])
print(myarray3)
print(myarray3[1, 0, 1])
print(myarray3[0,0,1])
# Slicing [start:stop:step]
myarray1
print(myarray1[1:])
print(myarray1[::-1])
print(myarray1[::2])
myarray2
print(myarray2[0:3,1])
print(myarray2[1: ,])
print(myarray2[ : ,1:])
print(myarray2[1: , 1: ])
## Special arrays
myarray = np.arange(10)
myarray
myarray = np.zeros(3)
print(myarray)
myarray = np.zeros((2,3))
myarray
myarray = np.ones((2,3))
myarray
myarray = np.eye(3)
myarray
myarray = np.linspace(1,5,10)
myarray
myarray.ndim
myarray = np.linspace(1,10,10)
myarray
myarray = np.linspace(1,10,6)
myarray
# reshaping
myarray = np.eye(4)
myarray
myarray.reshape((2,8))
myarray.reshape((2,9))
myarray.reshape(16)