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

``````nlat=10
mylist = []

for x in range(0,nlat):

for y in range(0,nlat):

disk=sphere(pos=(x*s,y*s), radius = r, color=(0,1,9))

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?

## Recommended Answers

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

``````nlat=10
mylist = []

for x in range(0,nlat):
tmp = []

for y in range(0,nlat):

disk=sphere(pos=(x*s,y*s), radius = r, color=(0,1,9))

tmp.append(disk)
mylist.append(tmp)``````

et voila! An array of …

## All 3 Replies

Numpy handles only numeric arrays, not object arrays.
I think VPython actually uses numpy/numeric internally.

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

``````nlat=10
mylist = []

for x in range(0,nlat):
tmp = []

for y in range(0,nlat):

disk=sphere(pos=(x*s,y*s), radius = r, color=(0,1,9))

tmp.append(disk)
mylist.append(tmp)``````

et voila! An array of spheres.

Jeff

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

``````x_list = []
y_list = []
for disk in array:
x_list.append(disk.x)
y_list.append(disk.y)``````

Solved!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.