我有一个numpy数组如下:
a= array([[2, 3],
[0, 2]])
并希望使用np.greater将每行中的“向量”与其他行进行比较,以便:
array([[False, False], <--- [2,3] compared with [2,3]
[True, True]], <--- [2,3] compared with [0,2]
[[False, False], <--- [0,2] compared with [2,3]
[False, False]]) <--- [0,2] compared with [0,2]
但是,如果我尝试r=(np.greater.outer(a,a))
,它会将a
中的每个数字与a
中的每个其他数字进行比较,以便:{/ p>
array([[[[False, False], <--- 2 compared with a
[ True, False]],
[[ True, False], <--- 3 compared with a
[ True, True]]],
[[[False, False], <--- 0 compared with a
[False, False]],
[[False, False], <--- 2 compared with a
[ True, False]]]], dtype=bool)
¿我怎样才能使外部比较行明智而不是元素呢?
答案 0 :(得分:4)
试试这个:
let shareButton = ShareButton<LinkShareContent>()
let content = LinkShareContent(url: URL(string: "https://stackoverflow.com/a/45263496/1724845")!)
shareButton.content = content
shareButton.frame = CGRect(x: 50.0, y: 25.0, width: 200, height: 40)
view.addSubview(shareButton)
这与更明确的代码相同:
a[:,np.newaxis] > a