1

I have 2 ND arrays:

x = zeros(shape=(N,9)); vx = zeros(shape=(N,9))

I also have 2 1D arrays:

x0 = [] # array with 9 elements
vx0 = [] # array with 9 elements

I want the following output:

x: [[ x0[0]  0.  0. ...,  0.  0.  0.][ x0[1]  0.  0. ...,  0.  0.  0.]... ]etc
vx : [[ vx[0]  0.  0. ...,  0.  0.  0.][ vx[1]  0.  0. ...,  0.  0.  0.]...]etc

I tried:

for k in range(8):
    x[k:0] = x[k:0] + x0[k]
    vx[k:0] = vx[k:0] + vx0[k]

print x

x[0] will be the first array in the x-array. x[0:0] will be the first element in the first list in the x-array

I get following output:

[[ 0.  0.  0. ...,  0.  0.  0.]
 [ 0.  0.  0. ...,  0.  0.  0.]
 [ 0.  0.  0. ...,  0.  0.  0.]
...] etc

But x0 contains floats different from 0.

Can someone help me with my issue or point me in the right direction?

EDIT: I used the Numpy module

13
  • You forgot to specify the language; I assume this is python. What do you expect x[0:0] and x[3:0] (etc.) to be in your loop over k? Commented Sep 18, 2016 at 23:19
  • x[0] will be the first array in the x-array. x[0:0] will be the first element in the first list in the x-array Commented Sep 19, 2016 at 16:12
  • zeros are not builtin. Seems you are using numpy, right? Commented Sep 19, 2016 at 16:12
  • yes correct, I used the numpy module. Commented Sep 19, 2016 at 16:14
  • 1
    Don't edit the answer into the question, and don't edit the title with "SOLVED" and other things. If @Jeon wants to get rep for this trivial fix, they can add an answer which you can accept. If Jeon doesn't want to, you should just delete your question as it is unlikely to help future readers. Commented Sep 19, 2016 at 16:32

0

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.