0

Here I have this where import data as arrays then, operates on those arrays with a function

import numpy as np

n1 = an array of 999 numbers
mass1= an array of 999 numbers
x1= an array of 999 numbers
y1=an array of 999 numbers
z1=an array of 999 numbers
dt=.0001
npoints=len(n1)
xn=0
step=1

for timedt in xrange(0,npoints-1):
     step=step


     for l in xrange(0,npoints-1):
         xn=xn

         f=x1,y1,z1[xn]+x1,y1,z1[step]

     xn=xn+1
     step=step+1

     print f

However, when I print out f, I just get a huge list set of numbers in the format

.....
-9.622302989262075e-07
0.00016890654402323984
2.261014843829707e-05
-0.00011706036947314393
-7.791712660429376e-05
1.0156155973842854e-05
0.00019244252361596046
-0.00019202953520118445
0.04082168851673397
-0.001675463103312094
-1.4584179607758451e-05
3.788355464183264
3.99516377369456e-05

But I want to make these numbers be one array. In additon if I print f outside of that loop, I only get the last number. 3.99516377369456e-05

But I want to be able to print all of them outside of the loop as an array.

np.asarray

doesn't work.

2
  • What shape and dtype do you want? Is n1 really an 'array' (as in numpy.ndarray), or just a sloppy way of saying list? Commented Feb 11, 2019 at 22:28
  • n1 is really an array. I don't think I care what shape I want. Commented Feb 11, 2019 at 22:31

1 Answer 1

1

The easiest way would possibly be:

f_array = []
for ...:
    ...
    for ...:
        f = ...
    f_array.append(f)

f_array = np.array(f_array)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this worked. I tried doing something similar, but I didn't add the last line.

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.