【发布时间】:2017-03-15 06:37:44
【问题描述】:
我有两个二维数字数组,即 (95,60) 维度中的纬度和经度。我正在尝试查找以下条件语句的索引。
ind = np.where(((lat >= 20.0 and lat <= 30.0) and (lon >= 90.0 and lon <= 100.0)))
我收到以下错误:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
我的 lat 数组包含这样的数据:
array([[ 19.13272095, 19.52386856, 19.8377533 , ..., 22.81465149,
22.80446053, 22.78530312],
[ 19.2490139 , 19.64085197, 19.95526123, ..., 22.93462563,
22.92414474, 22.90457916],
[ 19.36528587, 19.75781822, 20.07275009, ..., 23.05456543,
23.04379272, 23.02381706],
...,
[ 29.7395134 , 30.20263481, 30.57126617, ..., 33.85147858,
33.81478882, 33.75755692],
[ 29.85359764, 30.31761169, 30.68692398, ..., 33.97143555,
33.93445587, 33.87679672],
[ 29.9676609 , 30.4325695 , 30.80256653, ..., 34.09137726,
34.05410767, 33.99602509]], dtype=float32)
同样,lon 数组包含的数据如下:
array([[ 96.78914642, 98.04283905, 99.0661087 , ..., 119.39452362,
120.45418549, 121.74817657],
[ 96.75196075, 98.00632477, 99.03016663, ..., 119.37508392,
120.43569183, 121.73084259],
[ 96.71466064, 97.96970367, 98.99414062, ..., 119.35567474,
120.41724396, 121.71356201],
...,
[ 92.90063477, 94.2386322 , 95.33486176, ..., 117.72390747,
118.90248108, 120.34107971],
[ 92.85238647, 94.19155884, 95.2888031 , ..., 117.7070694 ,
118.88733673, 120.32800293],
[ 92.80393219, 94.14429474, 95.24256897, ..., 117.69021606,
118.87218475, 120.31491089]], dtype=float32)
我试图修改我的命令如下:
ind = np.where(((lat.all() >= 20.0 and lat.all() <= 30.0) and (lon.all() >= 90.0 and lon.all() <= 100.0)))
我得到以下空数组作为输出:
(array([], dtype=int64),)
我什至尝试过以下方法:
ind = np.where(lat.all() >= 20.0 and lat.all() <= 30.0)
输出为:(array([], dtype=int64),)
我不明白如何解决我的问题。谁能帮助我如何以及在哪里做错了?
【问题讨论】:
标签: arrays python-2.7 numpy