I’m learning to use python for data analysis, etc. and I am a little confused about what is going on in this code from the scipy cookbook.
When the cookbook describes the integration and then plotting process, via matplotlib, it has first:
t = linspace(0, 15, 1000)
X0 = array([10,5])
X = scipy.integrate.odeint(dX_dt, X0, t)
rabbits, foxes = X.T
What does this code do?
rabbits, foxes = X.T
Specifically, what does X.T do?
X.Tis the transpose ofX. So, in that line,Xmust be an array with shape(N,2). When you transpose it you get an array of shape(2,N)which can be unpacked.Consider:
Also note that wherever possible, the transpose will return a new view (the data won’t be copied), so this is a very efficient operation.