Reputation: 24764
In python, with numpy, I can generate a meshgrid
import numpy as np
import matplotlib.pyplot as plt
def main():
x = np.linspace(0, 10, 4)
y = np.linspace(0, 10, 4)
x,y = np.meshgrid(x,y)
print x,y
if __name__ == '__main__':
main()
and I get:
[[ 0. 3.33333333 6.66666667 10. ]
[ 0. 3.33333333 6.66666667 10. ]
[ 0. 3.33333333 6.66666667 10. ]
[ 0. 3.33333333 6.66666667 10. ]]
[[ 0. 0. 0. 0. ]
[ 3.33333333 3.33333333 3.33333333 3.33333333]
[ 6.66666667 6.66666667 6.66666667 6.66666667]
[ 10. 10. 10. 10. ]]
how I can get the elements (squares) of the meshgrid, with the vertex ?
example: the square upper-left have the vertexs
(0, 0) (0,3.3)
(3.3,0) (3.3, 3.3)
Upvotes: 3
Views: 1890
Reputation: 11
It's a bit late by a way for that is as followsnp.hstack((x.reshape((x.size,1)),y.reshape((y.size,1))))
Upvotes: 1
Reputation: 362617
I believe that would be
np.dstack([x,y])[row:row+2, col:col+2, :]
Where row, col
are the coordinates of the top-left corner for that square. Won't work on the last row or column, obviously.
Upvotes: 3