![](/img/trans.png)
[英]How to check if elements of a vector lies between two vectors in Numpy?
[英]Python: count how many times an element of a vector is in between of elements of two other vectors?
假設我有3個向量:
v1 = 1,6,7
v2 = 2,5,6
v3 = 3,4,2
我想計算v1[i] <= v2[i] <= v3[i]
(以Pythonic的方式)的次數。 對於以上示例,答案應為1
。
嘗試這個:
sum(v1[x] <= v2[x] <= v3[x] for x in range(3))
如果v1
, v2
等是numpy.arrays
,則可以執行
np.sum(np.logical_and(v1<v2, v2<v3))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.