Numy Session 6 Code For Video Click Fahad Hussain CS
import numpy as np
a=np.array([[1,4,7,10],
[2,5,8,11]])
print(np.mean(a))
b=np.std(a)
print(b)
a=np.array([[1,4,7,10],[2,5,8,11]])
b=np.std(a, axis=1)
b
import numpy as np
a = np.zeros((2, 512*512), dtype=np.float32)
a[1, :] = 1.0
a[0, :] = 0.1
print(a)
# dtype=np.float64
b=np.std(a)
print(b)
import numpy as np
x = np.arange(20).reshape(4,5) + 7
print(x)
y=np.argmax(a)
print(y)
import numpy as np
x = np.arange(20).reshape(4,5) + 7
print(x)
y=np.argmax(x, axis=0)
z=np.argmax(x, axis=1)
print(y)
print(z)
import numpy as np
x = np.arange(20).reshape(4,5) + 7
print(x)
indices = np.unravel_index(np.argmax(x, axis=None), x.shape)
indices
x[indices]
import numpy as np
arr = np.array([0, 1, 2], dtype=np.uint8)
print(arr)
b=np.diff(arr)
print(b)
print(arr[2,...] - arr[1,...] - arr[0,...] )
import numpy as np
x = np.array([[11, 21, 41],
[71, 1, 12],
[33, 2, 13]])
y = np.diff(x, axis=0)
print(y)
z = np.diff(x, axis=1)
print(z)
import numpy as np
x = np.arange('1997-10-01', '1997-12-16', dtype=np.datetime64)
y = np.diff(x)
y
import numpy as np
a=np.histogram([1, 5, 2], bins=[0, 1, 2, 3])
print(a)
import numpy as np
x=np.histogram(np.arange(6), bins=np.arange(7), density=True)
x
import numpy as np
a = np.arange(8)
hist, bin_edges = np.histogram(a, density=True)
print(hist)
print(bin_edges)
import numpy as np
x = [1,2,3]
y = np.pad(x, (3, 2), 'constant', constant_values=(6, 4))
y
import numpy as np
x = [1, 3, 2, 5, 4]
y = np.pad(x, (3, 2), 'edge')
y
import numpy as np
x = [1, 3, 2, 5, 4]
y = np.pad(x, (3, 2), 'linear_ramp', end_values=(-4, 5))
y
import numpy as np
x = [1, 3, 2, 5, 4]
# mean, median, minimum, maximum
y = np.pad(x, (3,4), 'median')
y
import numpy as np
x = np.array([[1, 3, 5], [11, 35, 56]])
print(x)
y=np.ravel(x)
y
import numpy as np
x = np.array([[1, 3, 5], [11, 35, 56]])
y = np.ravel(x, order='F')
z = np.ravel(x, order='C')
p = np.ravel(x, order='A')
q = np.ravel(x, order='K')
print(x)
print(y)
print(z)
print(p)
print(q)
import numpy as np
x = np.arange(12).reshape(3,2,2).swapaxes(1,2)
print(x)
y=np.ravel(a, order='C')
print(y)
z=np.ravel(a, order='K')
print(z)
q=np.ravel(a, order='A')
print(q )
import numpy as np
from tempfile import TemporaryFile
out_file = TemporaryFile()
x=np.arange(15)
print(x)
np.save(out_file, x)
_=out_file.seek(0) # Only needed here to simulate closing & reopening file
np.load(out_file)
import numpy as np
from tempfile import TemporaryFile
outfile = TemporaryFile()
x=np.arange(15)
np.save(outfile, x, allow_pickle=False)
_=outfile.seek(0) # Only needed here to simulate closing & reopening file
np.load(outfile)
No comments:
Post a Comment
Fell free to write your query in comment. Your Comments will be fully encouraged.