.T
transposes a matrix. So in your case, if n=2
, your code will work (or at least, will run without error) without the transpose, because a matrix such as:
>>> np.random.multivariate_normal(mean, cov, size = 2)
array([[ 1.4594626 , -0.55863612],
[-1.17139735, -0.36484634]])
Can be split into 2 arrays (x
will be [ 1.4594626 , -1.17139735]
and y
will be [-0.55863612, -0.36484634]
). Note that this is not necessarily what you are looking for, and you might end up plotting the wrong thing (depending what you're trying to do).
But for anything bigger (or smaller), it won't:
>>> np.random.multivariate_normal(mean, cov, size = 5)
array([[-0.34091962, 2.2368088 ],
[-1.11081547, 0.93089064],
[ 1.45452483, -0.40007311],
[ 0.96038401, 0.26206106],
[ 0.3079481 , 0.66869094]])
Because that is essentially 5 arrays that you are trying to unpack into 2 variables (hence the error). However when you transpose it:
>>> np.random.multivariate_normal(mean, cov, size = 5).T
array([[ 0.04466423, 0.88384196, 0.09108559, -2.30473587, 1.58497064],
[ 0.66190894, 0.90202853, 0.31090378, 0.95697681, -0.61557393]])
You're good to go. Your x
array will be the first "row": [ 0.04466423, 0.88384196, 0.09108559, -2.30473587, 1.58497064]
and y
will be your second: [ 0.66190894, 0.90202853, 0.31090378, 0.95697681, -0.61557393]