I often use theano.tensor.dimshuffle
. Is there an equivalent function for Numpy?
I guess I could do the same via several numpy.swapaxes
and numpy.newaxis
(for broadcast dimensions), numpy.reshape
but is there some simpler or more direct way, just like dimshuffle
?
The . T accesses the attribute T of the object, which happens to be a NumPy array. The T attribute is the transpose of the array, see the documentation.
The numpy. transpose() function changes the row elements into column elements and the column elements into row elements. The output of this function is a modified array of the original one.
The function numpy.transpose
permits any permutation of the axes of an array.
The variety array.T
is a special case of this, corresponding to array.transpose()
without arguments, which defaults to array.transpose(range(array.ndim)[::-1])
.
numpy.swapaxes
is numpy.transpose
restricted to permutations of two axes.
theano.tensor.dimshuffle
essentially corresponds to numpy.transpose
, but in addition, it permits the creation of new axes of length 1 for broadcasting, by adding 'x'
wherever an axis should be created. In numpy, this can be achieved using a combination of transpose
and reshape
.
Note that in numpy, care is taken to make transpose
return a view on the data whenever possible. In theano this is probably the case, too, but may depend on how the code is optimized.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With