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

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.