Home > OS >  Selecting a part of a 2d array of measured data depending on range of latitude and longitude on eart
Selecting a part of a 2d array of measured data depending on range of latitude and longitude on eart

Time:09-29

I have three arrays LATITUDE, LONGITUDE, data, with:

print(LATITUDE.shape, LONGITUDE.shape, data.shape)

(565, 1215) (565, 1215) (565, 1215)

whereby:

print(x.min(), y.min(), data.min(), x.max(), y.max(), data.max())

-55.530094 33.582264 0.0 55.530094 66.823235 275.67851091467816

How can I select values from 2d array data where ((LONGITUDE >=-20) & (LONGITUDE <=20) & (LATITUDE >=35) & (LATITUDE <=60))?

I tried the following:

indices = np.where((LONGITUDE >=-20) &  (LONGITUDE <=20) & (LATITUDE >=35) &  (LATITUDE <=60))

print(indices)

(array([ 28,  28,  28, ..., 540, 540, 540], dtype=int64), array([ 35,  36,  37, ..., 671, 672, 673], dtype=int64))

How can I apply this indices to data?

CodePudding user response:

Simply data[indices]

Example:

import numpy as np

x = np.random.uniform(0, 100, size=(100, 100))
y = np.random.uniform(0, 100, size=(100, 100))
data = np.random.randint(0, 1000, size=(100, 100))

indices = np.where((x >= -20) & (x <= 20) & (y >= 35) & (y <= 60))
print(data[indices])

  • Related