943,816 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 8821
  • Python RSS
Feb 19th, 2009
0

Convert python list to numpy array.

Expand Post »
Is there an easy way of doing this? for example my list is:

python Syntax (Toggle Plain Text)
  1. nlat=10
  2. mylist = []
  3.  
  4. for x in range(0,nlat):
  5.  
  6. for y in range(0,nlat):
  7.  
  8. disk=sphere(pos=(x*s,y*s), radius = r, color=(0,1,9))
  9.  
  10. mylist.append(disk)

or is it impossible to place objects, such as a sphere from vpython into a numpy array?, perhaps i could just put the x,y co-ordinates into a numpy array?
Similar Threads
Reputation Points: 11
Solved Threads: 2
Light Poster
breatheasier is offline Offline
46 posts
since Feb 2009
Feb 20th, 2009
-1

Re: Convert python list to numpy array.

Numpy handles only numeric arrays, not object arrays.
I think VPython actually uses numpy/numeric internally.
Reputation Points: 961
Solved Threads: 211
Nearly a Posting Maven
sneekula is offline Offline
2,413 posts
since Oct 2006
Feb 22nd, 2009
0

Re: Convert python list to numpy array.

Lists of lists work fine as container arrays (not mathematical arrays, but you don't seem to be wanting that). So:

Python Syntax (Toggle Plain Text)
  1. nlat=10
  2. mylist = []
  3.  
  4. for x in range(0,nlat):
  5. tmp = []
  6.  
  7. for y in range(0,nlat):
  8.  
  9. disk=sphere(pos=(x*s,y*s), radius = r, color=(0,1,9))
  10.  
  11. tmp.append(disk)
  12. mylist.append(tmp)

et voila! An array of spheres.

Jeff
Reputation Points: 92
Solved Threads: 156
Practically a Master Poster
jrcagle is offline Offline
608 posts
since Jul 2006
Feb 22nd, 2009
0

Re: Convert python list to numpy array.

I was wanting to extract a list of x and y values from the list. I did it like this simply:

python Syntax (Toggle Plain Text)
  1. x_list = []
  2. y_list = []
  3. for disk in array:
  4. x_list.append(disk.x)
  5. y_list.append(disk.y)

Solved!
Reputation Points: 11
Solved Threads: 2
Light Poster
breatheasier is offline Offline
46 posts
since Feb 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Help creating functions
Next Thread in Python Forum Timeline: How do i use the wxpython.scrolledPanel widget





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC