Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the parameter keepdims in Keras' backend functions used for?

Tags:

python

keras

There are many functions in the Keras backend which have the keepdims parameter. For instance

sum(x, axis=None, keepdims=False)

I can not find any explanation of what that means. Can someone explain what it does?

Also, what does it mean for axis to be None? Is it the same as saying axis = -1?

like image 687
chasep255 Avatar asked Jun 03 '16 23:06

chasep255


2 Answers

These are not keras specific parameters but numpy.sum parameters.

axis : None or int or tuple of ints, optional

Axis or axes along which a sum is performed. The default (axis = None) is perform a sum over all the dimensions of the input array. axis may be negative, in which case it counts from the last to the first axis.

New in version 1.7.0.

If this is a tuple of ints, a sum is performed on multiple axes, instead of a single axis or all the axes as before.

keepdims : bool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original arr.

here is the source

like image 74
EoinS Avatar answered Sep 27 '22 16:09

EoinS


You can find documentation and tutorial for theano (one of keras backends) in deeplearning.net

For method theano.tensor.sum, see here

theano.tensor.sum(x, axis=None, dtype=None, keepdims=False, acc_dtype=None)

axis - axis or axes along which to compute the sum

keepdims - (boolean) If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original tensor.

As pointed out by EoinS, theano functions are very similar to those of numpy.

like image 23
sytrus Avatar answered Sep 27 '22 17:09

sytrus