Numpy поэлементное сравнение

Привет, попробуйте async: false в вашем вызове ajax ..

2
задан Hello 19 March 2019 в 00:10
поделиться

1 ответ

Воспользуйтесь вещанием :

first = np.reshape(array, (*array.shape, 1, 1))
second = np.reshape(array, (1, 1, *array.shape))

result = (first > second)

Это даст array формы (*array.shape, *array.shape), где result[r1, c1, r2, c2] - это значение, которое вы хочет.

Пример:

array = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])

first = np.reshape(array, (*array.shape, 1, 1))
second = np.reshape(array, (1, 1, *array.shape))

result = (first > second)

print(result[0, 0, 1, 1]) # 1 > 6
print(result[1, 1, 0, 1]) # 6 > 2
print(result[0, 3, 0, 2]) # 3 > 2

Выход:

False
True
True
0
ответ дан gmds 19 March 2019 в 00:10
поделиться
Другие вопросы по тегам:

Похожие вопросы: