嵌套np.哪里和布尔数组索引问题

2024-05-06 17:41:12 发布

您现在位置:Python中文网/ 问答频道 /正文

概述:我很难理解使用此嵌套掩码的地方出了什么问题np.哪里. 我希望的是-如果雪是真的,分配1,如果错误评估第二个np.哪里,测试是否没有雪为真,则分配0,如果为假(表示雪为假,如果为假则无雪),则分配2。在

# open IMS & pull necessary keys.
hf = h5py.File(ims_dir + 'ims_daily_snow_cover.h5', 'r')
ims = hf['snow_cover'][...]


# create an empty parameter to be later written to new hdf file as gap_fill_flag.
dataset_fill = np.zeros(ims.shape)

# loop through fill - branch based on temporal fill or merra fill.
for day in range(len(fill)):
    # print len(day)
    print day
    fill[day] == 2
    year = days[day][:4]
    # merra fill - more than one consecutive day missing.
    if (fill[day-1] == 2) | (fill[day+1] == 2):
        # run merra_fill function
        # fill with a 2 to signify data are filled from merra.
        ims[day, :] = merra_fill(days[day], ims[day, :])
        dataset_fill[day, :] = 2
    else:
        # temporal_fill - less than one consecutive day missing.
        snow = ((ims[day - 1:day+2, :] == 1).sum(axis=0)) == 2
        no_snow = ((ims[day - 1:day+2, :] == 0).sum(axis=0)) == 2
        # nested np.where.
        ims[day, :] = np.where(snow == True, 1, np.where(no_snow == True, 0, 2))

        dataset_fill[day, :][ims[day, :] < 2] = 1
        dataset_fill[day, :][ims[day, :] == 2] = 2

        ims[day, :][ims[day, :] == 2] = merra_fill(days[day], ims[day, :])

错误:

^{pr2}$

帮帮我,斯塔克弗。你是我唯一的希望。在


Tags: tolen错误npcoverwheredaysfill
1条回答
网友
1楼 · 发布于 2024-05-06 17:41:12

从帮助(np.哪里)公司名称:

where(condition, [x, y])

Return elements, either from `x` or `y`, depending on `condition`.

If only `condition` is given, return ``condition.nonzero()``.

Parameters
     
condition : array_like, bool
    When True, yield `x`, otherwise yield `y`.
x, y : array_like, optional
    Values from which to choose. `x` and `y` need to have the same
    shape as `condition`.

我怀疑np.where(no_snow...)snow == True有相同的形状。在

相关问题 更多 >