'Numpy mgrid/ arange
I have a bunch of arrays around 10,000~ 10000000. each containing coordinates points x,y,z. I have successfully stored those in Numpy array. i have generated maxi and mini using
np.array(np.amin(Vertex_combined[:,:,:],axis=1))
np.array(np.amax(Vertex_combined[:,:,:],axis=1))
these generate 2 ranges
maxs=array([[406.78, 805.73, 345.14],
[407.57, 805.83, 345.14],
[407.9 , 805.83, 314.19]])
mins=array([[405.05, 805.52, 314.15],
[405.84, 805.62, 314.15],
[406.78, 805.19, 309.75]])
Now I need to generate
np.mgrid[mins[1,0]:maxs[1,0]:0.5, mins[1,1]:maxs[1,1]:0.5].reshape(2,-1).T
array([[405.84, 805.62],
[406.34, 805.62],
[406.84, 805.62],
[407.34, 805.62]])
this works for single array by when i try
np.mgrid[mins[:,0]:maxs[:,0]:0.5, mins[:,1]:maxs[:,1]:0.5].reshape(2,-1).T
doesn't work. Any help or explanation for what I'm doing wrong would be of great help. thank you,
Traceback (most recent call last):
File "C:\Users\R414065\AppData\Local\Programs\Python\Python38\lib\site-packages\numpy\lib\index_tricks.py", line 164, in __getitem__
int(math.ceil((kk.stop - start) / (step * 1.0))))
TypeError: only size-1 arrays can be converted to Python scalars
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
np.hstack(np.mgrid[mins[:,0]:maxs[:,0]:0.5, mins[:,2]:maxs[:,2]:0.5].reshape(2,-1).T)
File "C:\Users\R414065\AppData\Local\Programs\Python\Python38\lib\site-packages\numpy\lib\index_tricks.py", line 194, in __getitem__
step = key.step
AttributeError: 'tuple' object has no attribute 'step'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
