【发布时间】:2014-07-01 23:12:56
【问题描述】:
import numpy as np
data = np.array([[0, 0, 1, 1, 2, 2],
[1, 0, 0, 1, 2, 2],
[1, 0, 1, 0, 0, 0],
[1, 1, 0, 0, 2, 0]])
我该怎么做?
在 2 x 2 补丁内:
if any element is 2: put 2
if any element is 1: put 1
if all elements are 0: put 0
预期结果是:
np.array([[1, 1, 2],
[1, 1, 2]])
【问题讨论】:
-
到目前为止您尝试过什么?就目前而言,这看起来像是您在要求某人为您编写代码。
-
如果
1和2都出现在一个块中怎么办? -
@Lego Stormtroopr '就目前的样子' 是什么意思?抱歉,我的母语不是英语。
-
看起来您要求我们为您完成工作,因为没有代码。
-
@user2357112 因为第一步给了2个优先级,所以放了2个。
标签: python arrays numpy scipy scikit-learn