<jupyter_start><jupyter_text>![image.png](attachment:image.png)<jupyter_code># Consider an array of dimension (5,5,3), how to mulitply it by an array with dimensions (5,5)?
A = np.ones((5,5,3))
B = 2*np.ones((5,5))

print (A)
# Swap two rows of an array? 

A = np.arange(25).reshape(5,5)
print (A)
print (A[:2])
print (A[0])
x=A[0].copy()
A[0]=A[1]
A[1]=x
print (A)<jupyter_output>[[ 0  1  2  3  4]
 [ 5  6  7  8  9]
 [10 11 12 13 14]
 [15 16 17 18 19]
 [20 21 22 23 24]]
[[0 1 2 3 4]
 [5 6 7 8 9]]
[0 1 2 3 4]
[[ 5  6  7  8  9]
 [ 0  1  2  3  4]
 [10 11 12 13 14]
 [15 16 17 18 19]
 [20 21 22 23 24]]<jupyter_text>Special Data typesIn addition to dtype objects, NumPy introduces special numeric values: nan (not a number) and inf(infinity)<jupyter_code>What is the result of the following expression? 

0 * np.nan
np.nan == np.nan
np.inf > np.nan
np.nan - np.nan
0.3 == 3 * 0.1
0 * np.nan
np.nan == np.nan
np.inf > np.nan
np.nan - np.nan
0.3 == 3 * 0.1
3*0.10000000000000000
0.30000000000000004 == 3*0.1
import numpy as np
arr2d = np.array([[1, 2, 3],
                 [4, 5, 6],
                 [7, 8, 9]]) #3x3 matrix

# Retireve rows(0,1) , column (1rst onward)
# Sol 1:
print(arr2d[:2, 1:])
# Sol 2:
print(arr2d[ [0,1] , [1,2] ])
row = np.array([0,1])
col = np.array([1,2])
print("row=",row)
print("col=",col)
print("arr2d[row,col]=",arr2d[row,col])
print(arr2d[row[:, np.newaxis], col])<jupyter_output>[[2 3]
 [5 6]]
[2 6]
row= [0 1]
col= [1 2]
arr2d[row,col]= [2 6]
[[2 3]
 [5 6]]
StarcoderdataJupyterStructuredCleanDedup