0

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?

3
Contributors
3
Replies
5
Views
8 Years
Discussion Span
Last Post by breatheasier
-1

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

0

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

0

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!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.