목록Numpy (57)
Note
How to pretty print a numpy array by suppressing the scientific notation (like 1e10)? # Reset printoptions to default np.set_printoptions(suppress=False) # Create the random array np.random.seed(100) rand_arr = np.random.random([3,3])/1e3 # output array([[ 5.434049e-04, 2.783694e-04, 4.245176e-04], [ 8.447761e-04, 4.718856e-06, 1.215691e-04], [ 6.707491e-04, 8.258528e-04, 1.367066e-04]]) np.set_..
How to print only 3 decimal places in python numpy array? # Input rand_arr = np.random.random((5,3)) # Create the random array rand_arr = np.random.random([5,3]) # Limit to 3 decimal places np.set_printoptions(precision=3) rand_arr[:4] # output array([[ 0.443, 0.109, 0.97 ], [ 0.388, 0.447, 0.191], [ 0.891, 0.474, 0.212], [ 0.609, 0.518, 0.403]])
How to create a 2D array containing random floats between 5 and 10? # Input arr = np.arange(9).reshape(3,3) # 1: rand_arr = np.random.randint(low=5, high=10, size=(5,3)) + np.random.random((5,3)) # print(rand_arr) # 2: rand_arr = np.random.uniform(5,10, size=(5,3)) print(rand_arr) # output [[ 8.50061025 9.10531502 6.85867783] [ 9.76262069 9.87717411 7.13466701] [ 7.48966403 8.33409158 6.16808631..
How to reverse the columns of a 2D array? # Input arr = np.arange(9).reshape(3,3) # Solution arr[:, ::-1] # output array([[2, 1, 0], [5, 4, 3], [8, 7, 6]])