Instantly share code, notes, and snippets.

# karanjagota/numpy_example.pySecret Last active Jul 5, 2019

gist for my medium blogs
 import numpy as np # creating numpy array .. numpy_1d_array = np.array([1,2,3,4,5,6,7,8,9,10]) numpy_2d_array = np.array([[1,2],[3,4],[5,6],[7,8],[9,10]]) # basic numpy functions ie. print,type,shape print(numpy_1d_array , numpy_2d_array) # output [ 1 2 3 4 5 6 7 8 9 10] [[1,2][3,4][5,6][7,8][9,10]] print(numpy_1d_array.dtype , numpy_2d_array.dtype) #output int64 int64 print(numpy_1d_array.shape , numpy_2d_array.shape) # output (10,) (5, 2) # reshaping the 1-d array to 2-d array and vice_versa .. reshaped_numpy_1d_array = numpy_1d_array.reshape(5,2) reshaped_numpy_2d_array = numpy_2d_array.reshape(10,) # checking the new reshaped array ... print(reshaped_numpy_1d_array) # output :// [[ 1 2][ 3 4][ 5 6][ 7 8][ 9 10]] print(reshaped_numpy_2d_array) # output :// [1 2 3 4 5 6 7 8 9 10] # indexing and slicing array .. print(numpy_1d_array[5:]) # select values after index 5 ... # output [ 6 7 8 9 10] print(numpy_2d_array[1:]) # output [[ 3 4][ 5 6][ 7 8][ 9 10]] print(numpy_2d_array[0:1,1:2]) # selecting rows and columns # output [[2]]