''' Created on Dec 2, 2017 @author: bob ''' import numpy as np A= np.arange(36) print("original shape and array from arange\n",A.shape,"\n",A) A=A.reshape((4,3,3)) print("\n\n reshaped from arange \n",A.shape,"\n",A) B=A.reshape((-1,9)) print("\n\n new shape",B.shape ,"\narray \n",B) C=np.arange(4) print("original shape of label and array from arange\n",C.shape,"\n",C) D=np.array([0,3,2,1,0,3,2,3,1,0,2,1,0]) print("original shape and array from arange\n",D.shape,"\n",D) DR= D[:,None] print("\n Use of None on array\n",DR.shape,"\n",DR) OneHot= C==DR print("\n one hot encoding before change to 0,1\n",OneHot) # note what happens is that the DR array is expanded in the dimension (last ) that is 1 to match the 4 that is in C and then logical comparison is made ) print("\n one hot encoding \n",OneHot.astype(np.float32))