Numy Session 4 Code For Video Click Fahad Hussain CS
#### Builtin Function Numpy
import numpy as np
a=np.array([2, 4, 6, 3**8])
print(a)
b=np.log(a)
print(b)
c=np.log2(a)
print(c)
d=np.log10(a)
print(d)
import numpy as np
import matplotlib.pyplot as plt
arr = [2, 2.2, 2.4, 2.6,2.8, 3]
result1=np.log(arr)
result2=np.log2(arr)
result3=np.log10(arr)
plt.plot(arr,arr, color='blue', marker="*")
plt.plot(result1,arr, color='green', marker="o")
plt.plot(result2,arr, color='red', marker="*")
plt.plot(result3,arr, color='black', marker="*")
plt.show()
import numpy as np
x=np.log([2, np.e, np.e**3, 0])
x
import numpy as np
a=np.arange(12)
b=np.where(a<6,a,5*a)
b
# Broadcasting x, y, and condition
import numpy as np
a=np.arange(12)
b=np.where([[True, False], [True, True]],[[1, 2], [3, 4]],[[9, 8], [7, 6]])
b
import numpy as np
x, y = np.ogrid[:3, :4]
a=np.where(x > y, x, 10 + y)
a
x=np.array([[0,1,2],[0,2,5],[0,4,8]])
y=np.where(x<4,x,-2)
y
import numpy as np
a=np.array([456,11,63])
print(a)
b=np.argsort(a)
print(b)
import numpy as np
a = np.array([[0, 5],
[3, 2]])
indices = np.argsort(a, axis=0)
print(indices)
np.take_along_axis(a, indices, axis=0)
import numpy as np
a = np.array([[0, 5], [3, 2]])
indices = np.argsort(a, axis=1)
indices
import numpy as np
a = np.array([[0, 5], [3, 2]])
indices = np.argsort(a, axis=1)
indices
np.take_along_axis(a, indices, axis=1)
import numpy as np
a = np.array([[0, 5], [3, 2]])
indices = np.unravel_index(np.argsort(a, axis=None), a.shape)
indices
a[indices] # same as np.sort(a, axis=None)
import numpy as np
a= np.array([(0, 5), (3, 2)], dtype=[('x', '<i4'), ('y', '<i4')])
print(a)
b=np.argsort(a, order=('x','y'))
print(b)
c=np.argsort(a, order=('y','x'))
print(c)
import numpy as np
a= np.arange(6).reshape((2,3))
print(a)
b=np.transpose(a)
b
import numpy as np
a= np.array([[1, 2], [4, 5], [7, 8]])
a
b=np.transpose(a, (1,0))
print(b)
import numpy as np
a=np.ones((12,32,123,64))
print(a)
b=np.transpose(a,(1,3,0,2)).shape
print(b)
c=np.transpose(a,(0,3,1,2)).shape
print(c)
import numpy as np
a = np.array([[1, 1], [1, 1]])
b=np.mean(a)
print(b)
x = np.array([[5, 6], [7, 34]])
y=np.mean(x)
print(y )
import numpy as np
a = np.array([[2, 4],
[3, 5]])
b=np.mean(a,axis=0)
c=np.mean(a,axis=1)
print(b)
print(c)
import numpy as np
a = np.zeros((2, 512*512), dtype=np.float32)
a[0, :] = 23.0
a[1, :] = 32.0
c=np.mean(a)
c
import numpy as np
a[0, :] = 2.0
a[1, :] = 0.2
c=np.mean(a)
print(c)
d=np.mean(a, dtype=np.float64)
print(d)
No comments:
Post a Comment
Fell free to write your query in comment. Your Comments will be fully encouraged.