Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference of numpy.ndarray.T and numpy.ndarray.transpose() when self.ndim < 2

Tags:

python

numpy

The document numpy.ndarray.T says

ndarray.T — Same as self.transpose(), except that self is returned if self.ndim < 2.

Also, ndarray.transpose(*axes) says

For a 1-D array, this has no effect.

Doesn't this mean the same thing?

Here's a little demo snippet:

>>> import numpy as np >>> print np.__version__ 1.5.1rc1 >>> a = np.arange(7) >>> print a, a.T, a.transpose() [0 1 2 3 4 5 6] [0 1 2 3 4 5 6] [0 1 2 3 4 5 6] 
like image 821
lotrpy Avatar asked Nov 01 '10 10:11

lotrpy


People also ask

What is difference between .T and transpose () in NumPy?

T is just a convenient notation, and that . transpose(*axes) is the more general function and is intended to give more flexibility, as axes can be specified.

What is Ndarray NDIM?

ndarray. ndim() function return the number of dimensions of an array.

What is the difference between NumPy array and Ndarray?

numpy. array is just a convenience function to create an ndarray ; it is not a class itself. You can also create an array using numpy. ndarray , but it is not the recommended way.

What does NumPy t mean?

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. Apparently you are creating random coordinates in the plane.


1 Answers

Regardless of rank, the .T attribute and the .transpose() method are the same—they both return the transpose of the array.

In the case of a rank 1 array, the .T and .transpose() don't do anything—they both return the array.

like image 72
Matthew Rankin Avatar answered Oct 19 '22 12:10

Matthew Rankin