chasep255
chasep255

Reputation: 12185

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

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?

Upvotes: 5

Views: 2077

Answers (2)

sytrus
sytrus

Reputation: 777

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.

Upvotes: 1

EoinS
EoinS

Reputation: 5482

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

Upvotes: 4

Related Questions