检查列表中的第一个或第二个元素是否具有相同的数据类型。

时间:2019-06-07 15:43:01

标签: prolog

我是Prolog的初学者。我有自定义类型的鸟,鱼,动物。所以问题是我想传递诸如firstLast([owl,chicken,cat,eagle])之类的函数并获得结果为true,因为first和last是相同的数据类型。再举一个例子:

firstLast([dog,owl,shark,eagle,cat]).
> true

firstLast([shark,dog,owl,mouse]).
> false

这是我的基本数据:

bird(eagle).
bird(chicken).

animal(cat).
animal(mouse).
animal(dog).

fish(shark).
fish(wheal).
fish(goldfish).

isSameType(X,Y):-
   (  bird(X),bird(Y)
   ;  animal(X),animal(Y)
   ;  fish(X),fish(Y)
   ).

1 个答案:

答案 0 :(得分:0)

这应该可以使用last/2

variable = 'precip'
rank_norm_list = []

# loop through all the months
for mth in range(1, 13):
    # select that month
    ds_mth = (
        ds
        .where(ds['time.month'] == mth)
        .dropna(dim='time', how='all')
    )
    # apply the function to that month (here a normalised rank (0-100))
    rank_norm_mth = (
        (ds_mth.rank(dim='time') - 1) / (ds_mth.time.size - 1.0) * 100.0
    )
    rank_norm_mth = rank_norm_mth.rename({variable: 'rank_norm'})
    rank_norm_list.append(rank_norm_mth)

# after the loop re-combine the DataArrays
rank_norm = xr.merge(rank_norm_list).sortby('time')

Out[]:
<xarray.Dataset>
Dimensions:    (lat: 10, lon: 10, time: 108)
Coordinates:
  * time       (time) datetime64[ns] 2010-01-31 2010-02-28 ... 2018-12-31
  * lat        (lat) float64 -5.175 -5.125 -5.075 ... -4.825 -4.775 -4.725
  * lon        (lon) float64 33.52 33.57 33.62 33.67 ... 33.82 33.87 33.92 33.97
Data variables:
    rank_norm  (time, lat, lon) float64 75.0 75.0 12.5 100.0 ... 87.5 0.0 25.0