2 views
in Python

In the assistance asset for the multivariate normal sampling function in SciPy, they give the accompanying example:

x,y = np.random.multivariate_normal(mean,cov,5000).T

My question is fairly fundamental: what does the last .T really do?

Thank you in advance, I realize it is genuinely straightforward. However, it is difficult to glance in Google for ".T".

by (26.4k points)

The .T gets to the property T of the object, which turns out to be a NumPy array. The T attribute is the render of the array, see the documentation

Obviously, you are making arbitrary coordinates in the plane. The yield of multivariate_normal() may resemble this:

>>> np.random.multivariate_normal([0, 0], [[1, 0], [0, 1]], 5)

array([[ 0.59589335,  0.97741328],

[-0.58597307,  0.56733234],

[-0.69164572,  0.17840394],

[-0.24992978, -2.57494471],

[ 0.38896689,  0.82221377]])

Below was the transpose of this matrix,

array([[ 0.59589335, -0.58597307, -0.69164572, -0.24992978,  0.38896689],

[ 0.97741328,  0.56733234,  0.17840394, -2.57494471,  0.82221377]])

Interested to learn the concepts of python in detail? Come and join the python course to gain more knowledge in python

Watch this video tutorial on how to become a professional in python