Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

NUMPY ASSIGNMENT

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:

Gives the absolute value

import numpy as np

x=np.array([-2.4, 4.1])

np.absolute(x)

[2.4, 4.1]

3. Transpose

It changes rows to columns and columns to rows

import numpy as np
a=np.array([[1, 2, 3], [4, 5, 6]])
np.transpose(a)

output

array([[1, 4], [2, 5], [3, 6]])

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

Print sine of one angle:


#sin function ranges from -1 to +1
X=np.array([5, 6])
import matplotlib.pylab as plt
import numpy as np
plt.plot(x, np.sin(x))
plt.show()

6. VSTACK

It combines two array in a row

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

It combines two array in a row

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)

You might also like