Arithmetic operations

  1. Add all the elements of the array with the sum method. Go back to array_1:
array_1array([[ 1,  2],       [ 3,  4],       [ 5,  6],       [ 7,  8],       [ 9, 10]])array_1.sum()55
  1. Find all the sums by row:
array_1.sum(axis = 1)array([ 3,  7, 11, 15, 19])
  1. Find all the sums by column:
array_1.sum(axis = 0)array([25, 30])
  1. Find the mean of each column in a similar way. Note that the dtype of the array of averages is np.float:
array_1.mean(axis = 0)array([ 5.,  6.])

Get scikit-learn Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.