Professional Documents
Culture Documents
Assignment Numpy
Assignment Numpy
1. RAVEL
It acts as reshape
import numpy as np
a=np.array([[1, 2, 3],[4, 5, 6]])
print(np.ravel(a))
output:
[1 2 3 4 5 6]
2.Absolute:
import numpy as np
x=np.array([-2.4, 4.1])
np.absolute(x)
[2.4, 4.1]
3. Transpose
import numpy as np
a=np.array([[1, 2, 3], [4, 5, 6]])
np.transpose(a)
output
4. UNWRAP
import numpy as np
a=np.array([[1, 2, 3], [4, 5, 6]])
np.unwrap(a)
output:
array([[ 1., 2., 3.], [ 4., 5., 6.]]
5. Sin function
6. VSTACK
import numpy as np
a=np.array([1, 2, 3])
b=np.array([2, 3, 4])
np.vstack((a,b))
output:
array([[1, 2, 3], [2, 3, 4]])
7. VSTACK
import numpy as np
a=np.array([1, 2, 3])
b=np.array([2, 3, 4])
np.hstack((a,b))
output:
array([1, 2, 3, 2, 3, 4])
8. BLOCK
Block behaves differently depending upon the argument that we pass
With a list of depth 1, it acts as hstack
import numpy as np
a=np.array([1, 2, 3])
b=np.array([2, 3, 4])
np.block([a, b, 10])
output:
array([ 1, 2, 3, 2, 3, 4, 10])
9. VSPLIT
It splits array(atleast 2D)into arrays
import numpy as np
a=np.array([[1, 2, 3],[4, 5, 6]])
output:
[array([[1, 2, 3]]), array([[4, 5, 6]])]
10. STRIDES
The strides of an array tell us how many bytes we have to skip in memory to move to the next position
along a certain axis
import numpy as np
a=np.array([[1, 2, 3],[4, 5, 6]])
a.strides
output:
(12, 4)