0

I am trying to store the numpy.ndarrays defined as x_c, y_c, and z_c for every iteration of the loop:

for z_value in np.arange(0, 5, 1):
    ms.set_current_mesh(0) 
    planeoffset : float = z_value 
    ms.compute_planar_section(planeaxis = 'Z Axis', planeoffset = planeoffset)
    m = ms.current_mesh()
    matrix_name = m.vertex_matrix()
    x_c = matrix_name[:,0]
    y_c = matrix_name[:,1]
    z_c = matrix_name[:,2]

I would like to be able to recall the three arrays at any z_value, preferably with reference to the z_value i.e x_c @ z_value = 2 or similar.

Thanks for any help!

p.s very new to coding, so please go easy on me.

Karl
  • 1,074
  • 8
  • 25
  • Welcome to SO. You need to properly indent you loop, as it is difficult to guess what is inside or outside of the loop. And what do you mean by "store" the arrays? Do you mean in a variable? Or store "on the computer" for later use by another program? – Karl Oct 20 '21 at 09:05
  • Hey Karl! Everything is inside the loop, sorry for not being clear. Store them in a variable so I can recall them using print() for example. Thanks. – niallmitchell Oct 20 '21 at 09:15

1 Answers1

0

You have to store each array in an external variable, for example a dictionary

x_c={}
y_c={}
z_c={}
for z_value in np.arange(0, 5, 1):
    ms.set_current_mesh(0)
    planeoffset = float(z_value)
    ms.compute_planar_section(planeaxis = 'Z Axis', planeoffset = planeoffset)
    m = ms.current_mesh()
    m.compact()
    print(m.vertex_number(), "vertices in Planar Section Z =", planeoffset)

    matrix_name = m.vertex_matrix()
    x_c[planeoffset] = matrix_name[:,0]
    y_c[planeoffset] = matrix_name[:,1]
    z_c[planeoffset] = matrix_name[:,2]

Please, ensure you call m.compact() before accessing the vertex_matrix or you will get a MissingCompactnessException error. Please, note that it is not the same to store anything in x_c[2] or in x_c[2.0], so choose if your index has to be integers o floats and keep the same type (in this example, they are floats).

Later, you can recall values like this:


print("X Values with z=2.0")
print(x_c[2.0])
Rockcat
  • 3,002
  • 2
  • 14
  • 28