Masked Array - 计算特定间隔内的值

发布于 2025-01-17 04:40:36 字数 743 浏览 0 评论 0原文

我对屏蔽数组和卫星数据很陌生。我试图弄清楚如何计算 masked_array 中介于某个间隔(例如 40 到 80)之间的元素数量。这就是我所拥有的:

这是名为“grid”的 masked 数组的摘要。

masked_array(
  data=[[[120, 120, 120, ..., 200, 200, 200],
         [120, 120, 120, ..., 200, 200, 200],
         [120, 120, 120, ..., 200, 200, 200],
         ...,
         [120, 120, 120, ..., 200, 200, 200],
         [120, 120, 120, ..., 200, 200, 200],
         [120, 120, 120, ..., 200, 200, 200]]],
  mask=False,
  fill_value=999999,
  dtype=uint8)

我想计算 masked_array 中 40 到 80 之间的元素的百分比。我尝试过。

masked  = ma.masked_where((grid >= 40) & (grid <= 80), grid)
green_ratio = masked.count()/grid.count()

但这返回 1,这是不太可能的,因为我看到有大于 120 的值。

知道如何执行此操作吗?

I am quite new to masked arrays and satellite data. I am trying to figure out how to count the number of elements in a masked_array that are in between an interval e.g. say 40 to 80. This is what I have:

This is the summary of my masked array named 'grid'.

masked_array(
  data=[[[120, 120, 120, ..., 200, 200, 200],
         [120, 120, 120, ..., 200, 200, 200],
         [120, 120, 120, ..., 200, 200, 200],
         ...,
         [120, 120, 120, ..., 200, 200, 200],
         [120, 120, 120, ..., 200, 200, 200],
         [120, 120, 120, ..., 200, 200, 200]]],
  mask=False,
  fill_value=999999,
  dtype=uint8)

I want to calculate the % of elements in the masked_array that are between 40 and 80. I tried.

masked  = ma.masked_where((grid >= 40) & (grid <= 80), grid)
green_ratio = masked.count()/grid.count()

but this is returning 1 which is quite unlikely given that I see that there are values larger than 120.

Any idea on how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骄兵必败 2025-01-24 04:40:36

masked.count() 仍然为您提供未过滤的值总数,当然等于 grid.count() 。

由于 masked.mask 是一个布尔数组,因此您可以执行例如 masked.mask.sum()/grid.count() 来限制满足条件的值的比率你的情况。

masked.count() still gives you the total unfiltered number of values which is of course equal to grid.count().

Since masked.mask is a boolean array, you could do for example masked.mask.sum()/grid.count() to limit the ratio to those values which meet your condition.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文