In order to store many 3D points coordinates tuples in a numpy.ndarray I initialize an empty numpy array before entering a loop for each of some features.
To do so, I currently do this before entering the loop:
import numpy as np
pointsarrray = np.empty((1,3))
but this results in an array which is all but empty:
array([[ 5.30498948e-315, 0.00000000e+000, 7.81250000e-003]])
When filling pointsarray in my loop after, I do this:
pointsarray = np.vstack((pointsarray, [np.array(myPoint)]))
(it also works with np.append)
and I finally need to delete the first line of the array after exiting the loop because this first line always contains the values from the initialization step!
It's not a big deal but I wonder if there is a cleaner way to achieve a really empty array, I mean; with nothing inside it (it shows 1 row yet, I can not figure out why) but at the right dimensions?
You need the shape to be (0, 3) so you have the correct number of columns to stack but have actually no data inside:
import numpy as np
pointsarrray = np.empty((0,3))
pointsarrray
# array([], shape=(0, 3), dtype=float64)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With