title: NumPy equivalent to Keras function utils.to_categorical
body: <p>I have a Python script which uses Keras for machine learning. I am building X and Y which are features and labels respectively.</p>
  <p>The labels are built like this:</p>
  <pre><code>def main=():
  
     depth = 10
     nclass = 101
     skip = True
     output = &quot;True&quot;
     videos = 'sensor'
     img_rows, img_cols, frames = 8, 8, depth
     channel = 1 
     fname_npz = 'dataset_{}_{}_{}.npz'.format(
      nclass, depth, skip)
  
     vid3d = videoto3d.Videoto3D(img_rows, img_cols, frames)
     nb_classes = nclass
  
     x, y = loaddata(videos, vid3d, nclass,
                      output, skip)
  
     X = x.reshape((x.shape[0], img_rows, img_cols, frames, channel))
     Y = np_utils.to_categorical(y, nb_classes) # This needs to be changed
  </code></pre>
  <p>The used function &quot;to_categorical&quot; in Keras is explain as follows:</p>
  <blockquote>
  <p>to_categorical</p>
  <p>keras.utils.to_categorical(y, num_classes=None)</p>
  <p>Converts a class vector (integers) to binary class matrix.</p>
  </blockquote>
  <p>Now I am using NumPy. May you let me know how the build the same line of code in order to work? In other words, I am looking for the equivalent of the &quot;to_categorical&quot; function in NumPy.</p>