11 - 2revision and Assessment Numpy
11 - 2revision and Assessment Numpy
11 - 2revision and Assessment Numpy
import numpy as np
Array Preparation
# np.array([10,20,30,40,50])
# np.zeros((5,3))
# np.ones((5,3,6))
np.arange(2,10,0.2)
array([2. , 2.2, 2.4, 2.6, 2.8, 3. , 3.2, 3.4, 3.6, 3.8, 4. , 4.2, 4.4,
4.6, 4.8, 5. , 5.2, 5.4, 5.6, 5.8, 6. , 6.2, 6.4, 6.6, 6.8, 7. ,
7.2, 7.4, 7.6, 7.8, 8. , 8.2, 8.4, 8.6, 8.8, 9. , 9.2, 9.4, 9.6,
9.8])
ar = np.linspace(2,10,60)
ar.size
60
ar.shape = (12,5,1,1)
ar.ndim
# np.random.randint(20,90,(10,2))
array(['i', 'g', 'f', 'j', 'e', 'd', 'b', 'h', 'c', 'a'], dtype='<U1')
array(['b', 'a', 'a', 'a', 'a', 'c', 'b', 'a', 'a', 'a'], dtype='<U1')
ar = np.random.normal(70,2,10).round(1)
ar.shape
(10,)
ar1 = ar.reshape(-1,1)
ar1.shape
ar1.ndim
x = np.linspace(-3,3,40)
y = x**2 + 1
yy = y + noise
# plt.plot(x,y)
plt.scatter(x,yy)
<matplotlib.collec�ons.PathCollec�on at 0x27291d740a0>
10
-3 -2 -1 0 1 2 3
np.random.rand(5)
ar = np.arange(10,70).reshape(3,4,5)
ar
ar[1][2][1:3]
array([41, 42])
ar[1,2,1:3]
array([41, 42])
ar[1][1:3]
ar[1,1:3,1]
array([36, 41])
ar[1,1,3].ndim
ar
arr = np.arange(24).reshape(2,3,4)
arr
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]],
np.sum(arr, axis=0)
np.sum(arr, axis=1)
np.sum(arr, axis=2)
np.sum(arr, axis=1).shape
(2, 4)