0

I wonder if there is a way to set up a NumPy linspace function with multiple num parameters so that I can create sequence of evenly spaced values with different intervals without any for loop operations.

To illustrate a bit more my issue, I have the following np.array for which I want to subdivide 3 segments represented by their 2 respective vertices on the x,y,z axis:

*************************
3D SEGMENTS TO DISCRETIZE
*************************
SegmentToDiscretize = np.array([[[150.149, 167.483,   4.2  ],[160.149, 167.483,   4.2  ]],
                                [[148.594, 163.634,  25.8  ],[180.547, 170.667,  25.8  ]],
                                [[180.547, 170.667,  25.8  ],[200.547, 190.667,  25.8  ]]])

And the folling function dedicated to add equidistant points between each pairs of vertices:

******************************
EQUIDISTANT POINTS COMPUTATION
******************************
nbsubdiv = 10

addedpoint = np.linspace(SegmentToDiscretize[:,0],SegmentToDiscretize[:,1],nbsubdiv, dtype = np.float)

Thanks to the argument nbsubdiv, I can specify how many subdivisions I want.
But I would like to specify 3 different subdivision values for each segments/rows contained in my SegmentToDiscretize np.array

[[[150.149, 167.483,   4.2  ],[160.149, 167.483,   4.2  ]],   <-- nbsubdiv = 4
[[148.594, 163.634,  25.8  ],[180.547, 170.667,  25.8  ]],    <-- nbsubdiv = 30
[[180.547, 170.667,  25.8  ],[200.547, 190.667,  25.8  ]]]    <-- nbsubdiv = 10

I tried to transform my nbsubdiv parameter as a list but without success...

nbsubdiv = [4,30,10]

addedpoint = np.linspace(SegmentToDiscretize[:,0],SegmentToDiscretize[:,1],nbsubdiv[0], dtype = np.float)

With the above code, I obtain :

[[148.594      163.634        4.2       ]
 [150.149      165.97833333   4.2       ]
 [153.48233333 167.483        4.2       ]
 [156.81566667 167.483        4.2       ]
 [159.245      167.483       25.8       ]
 [160.149      167.483       25.8       ]
 [169.896      168.32266667  25.8       ]
 [180.547      170.667       25.8       ]
 [180.547      170.667       25.8       ]
 [187.21366667 177.33366667  25.8       ]
 [193.88033333 184.00033333  25.8       ]
 [200.547      190.667       25.8       ]]

Which is normal since nbsubdiv[0] takes the first element in the list. But I did not succeeded in finding a way to use each values in this list recursively without a for loop.

So I would be very delighted if anyone could help me solve this challenge. Thanks in advance

Warm regards,

Hervé

RV-G
  • 21
  • 5
  • `linspace` returns an array. Originally it was 1d, now you can specify array start and stop. But the `num` must be a scalar. It can't be a multidimensional array otherwise. You can't have one 10 element row and another 11 in a 2d array! – hpaulj Feb 19 '20 at 18:26
  • Thanks @hpaulj for your first reply. So if I understand well, for now it's not possible to use a `np.array` to contain 3 different values to be affected on each respective SegmentToDiscretize np.array rows ? – RV-G Feb 19 '20 at 18:39

0 Answers0