i have this :
npoints=10
vectorpoint=random.uniform(-1,1,[1,2])
experiment=random.uniform(-1,1,[npoints,2])
and now i want to create an array with dimensions [1,npoints].
I can’t think how to do this.
For example table=[1,npoints]
Also, i want to evaluate this:
for i in range(1,npoints):
if experiment[i,0]**2+experiment[i,1]**2 >1:
table[i]=0
else:
table[i]=1
I am trying to evaluate the experiment[:,0]**2+experiment[:,1]**2 and if it is >1 then an element in table becomes 0 else becomes 1.
The table must give me sth like [1,1,1,1,0,1,0,1,1,0].
I can’t try it because i can’t create the array “table”.
Also,if there is a better way (with list comprehensions) to produce this..
Thanks!
Try:
You can leave off the
astype(int)call if you’re happy with an array of booleans rather than an array of integers. As Joe Kington points out, this can be simplified to:If you really need to create the
tablearray up front, you could do:(assuming that you’ve already import
zerosfrom numpy). Then your for loop should work as written.Aside: I suspect that you want
range(npoints)rather thanrange(1, npoints)in yourforstatement.Edit: just noticed that I had the 1s and 0s backwards. Now fixed.