import numpy as np
arr = np.random.randint(1,10,[3,3])
arr
print(arr.T)
print(np.transpose(arr))
print(arr.transpose())
arr1 = np.array([[2, 4, 6]])
arr1
np.swapaxes(arr1, 0, 1)
arr1 = np.arange(16).reshape((2,2,4))
arr1
np.swapaxes(arr1, 0, 1)
# change the shape of an array and return a copy
arr = np.arange(12)
arr
arr.reshape((2,6))
# change the shape of an array in place
arr.resize((2,6))
arr
# return a copy
arr.flatten()
# return a view
# change any element in the view will change the initial array
arr.ravel()
arr = np.array([1,2,3])
# append a scalar and return a copy
arr1 = np.append(arr, 4)
print(arr1)
# append an array and return a copy
arr2 = np.append(arr, [4,5,6])
print(arr2)
# np.insert(array, position, element)
# insert a scalar at a certain position
arr3 = np.insert(arr, 0, 100)
print(arr3)
# insert multiple values at a certain position
arr3 = np.insert(arr, 0, [1,2,3])
print(arr3)
# remove the element at position 0
arr4 = np.delete(arr, 0)
print(arr4)
# remove the element at multiple positions
arr4 = np.delete(arr, [0,2])
print(arr4)
arr = np.array([1,2,3])
# the following methods are all deep copy
arr1 = np.copy(arr)
# or
arr1 = arr.copy()
# or
arr1 = np.array(arr, copy=True)