0

Could I find a function in numpy achieved generating a 2-D map matrix by length and width array

for example, The length and width array of the rectangle:

length_point =[1, 2, 3]
width_point =[4, 5]

shape_length=(n,) shape_width=(m, )

then got result_shape=(n*m, 2),the pairs of point in result represents the point in the rectangle , just like latitude and longitude in map

result_point =[[1, 4], 
               [1, 5], 
               [2, 4], 
               [2, 5], 
               [3, 4], 
               [3, 5]]
jzw0659
  • 25
  • 1
  • 1
  • 5

1 Answers1

1

A possible approach, which involves three Numpy functions, hence potentially not what you are looking for, but it still does the job:

>>> np.column_stack((np.repeat(length_point, len(width_point)),
                     np.tile(width_point, len(length_point))))
array([[1, 4],
       [1, 5],
       [2, 4],
       [2, 5],
       [3, 4],
       [3, 5]])

repeat repeats the elements, while tile repeats the array, and column_stack is used to generate the desired concatenation.

Patol75
  • 4,342
  • 1
  • 17
  • 28