Convert python list to numpy array.

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2009
Posts: 44
Reputation: breatheasier is an unknown quantity at this point 
Solved Threads: 2
breatheasier's Avatar
breatheasier breatheasier is offline Offline
Light Poster

Convert python list to numpy array.

 
0
  #1
Feb 19th, 2009
Is there an easy way of doing this? for example my list is:

  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?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,297
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 178
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: Convert python list to numpy array.

 
0
  #2
Feb 20th, 2009
Numpy handles only numeric arrays, not object arrays.
I think VPython actually uses numpy/numeric internally.
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 150
jrcagle jrcagle is offline Offline
Practically a Master Poster

Re: Convert python list to numpy array.

 
0
  #3
Feb 22nd, 2009
Lists of lists work fine as container arrays (not mathematical arrays, but you don't seem to be wanting that). So:

  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
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 44
Reputation: breatheasier is an unknown quantity at this point 
Solved Threads: 2
breatheasier's Avatar
breatheasier breatheasier is offline Offline
Light Poster

Re: Convert python list to numpy array.

 
0
  #4
Feb 22nd, 2009
I was wanting to extract a list of x and y values from the list. I did it like this simply:

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

Solved!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 2075 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC