如何检查数组中是否存在数组?

时间:2019-01-26 13:52:11

标签: python

我正在尝试在if语句中读取数组。我已经读过,有一些方法可以以pythonic方式创建for循环,以便可以在if语句中使用它。

首先,我有一个看起来像Click here的np.array,然后为看起来像这样的高级图块制作了另一个数组

premium_tiles_word = np.array([['3','1','1','2','1','1','1','3','1','1','1','2','1','1','3'],
                             ['1','2','1','1','1','3','1','1','1','3','1','1','1','2','1'],
                             ['1','1','2','1','1','1','2','1','2','1','1','1','2','1','1'],
                             ['2','1','1','2','1','1','1','2','1','1','1','2','1','1','2'],
                             ['1','1','1','1','2','1','1','1','1','1','2','1','1','1','1'],
                             ['1','3','1','1','1','3','1','1','1','3','1','1','1','3','1'],
                             ['1','1','2','1','1','1','2','1','2','1','1','1','2','1','1'],
                             ['3','1','1','2','1','1','1','2','1','1','1','2','1','1','3'],
                             ['1','1','2','1','1','1','2','1','2','1','1','1','2','1','1'],
                             ['1','3','1','1','1','3','1','1','1','3','1','1','1','3','1'],
                             ['1','1','1','1','2','1','1','1','1','1','2','1','1','1','1'],
                             ['2','1','1','2','1','1','1','2','1','1','1','2','1','1','2'],
                             ['1','1','2','1','1','1','2','1','2','1','1','1','2','1','1'],
                             ['1','2','1','1','1','3','1','1','1','3','1','1','1','2','1'],
                             ['3','1','1','2','1','1','1','3','1','1','1','2','1','1','3']])

然后,我编写了一个代码来获取二和三的坐标,即doubles = np.argwhere(premium_tiles_word == '2') triples = np.argwhere(premium_tiles_word == '3')然后,我也使用coordinate_tiles = np.argwhere(arr1 != '0')得到了输出np数组的坐标获取坐标,我尝试使用

来比较双精度数和坐标,以获取具有图块的特定坐标
result = []
for x,y in coordinate_tiles:
    for a,b in doubles:
        if x==a and y ==b:
            result.append([x, b])

最后,我使用此算法来获得积分,从而获得鹰和苹果的积分。前言是输出np.array

for words in prevword:
    for word in words:
        if words == prevword[m + 1]:
           sum1 = sum1 + points_dictionary[word]
           if result == doubles:
              sum1 = sum1*2
           elif result == triples:
              sum1 = sum1*3

如何检查包含特定数组的结果是否具有与双打相同的数组之一?三倍?例如结果= [7,7],双打也有[7,7]

0 个答案:

没有答案