0

I have an ode equation which produces a list like below:

u=[array([ 2.06642033, -0.03448756]), 
   array([ 2.03964994, -0.18737285]), 
   array([ 1.99884859, -0.21461016]), 
   array([ 1.95476809, -0.2254584 ]), 
   array([ 1.90875336, -0.23472173]), 
   array([ 1.86082857, -0.24471069]),
   ... ]

I want to plot u[0] and u[1] based on time. I try to access all first and second elements of u in two list with l1=u[0:len(u)-1][0] and l2=u[0:len(u)-1][1], but it gives me only the first item from list. Does anyone have a solution for it? Thanks

2
  • What do you mean when you say "based on time"? Please provide some examples. Commented Apr 9, 2018 at 9:39
  • 1
    I have a time list which has the same length as u, like this: t=[0,0.001, ...] Commented Apr 9, 2018 at 9:40

1 Answer 1

4

You should convert your list of arrays into a single numpy array.

Also note that numpy array indexing in 2d is performed by arr[row, column]. If you don't filter by a dimension, just use :.

from numpy import array

u = [array([ 2.06642033, -0.03448756]), array([ 2.03964994, -0.18737285]),
     array([ 1.99884859, -0.21461016]), array([ 1.95476809, -0.2254584 ]),
     array([ 1.90875336, -0.23472173]), array([ 1.86082857, -0.24471069])]

u = np.array(u)

res = u[:, 0]

# array([ 2.06642033,  2.03964994,  1.99884859,  1.95476809,  1.90875336,
#         1.86082857])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.