Say I have 3 vectors:
v1 = 1,6,7
v2 = 2,5,6
v3 = 3,4,2
I want to count how many times that v1[i] <= v2[i] <= v3[i]
(in a Pythonic way of course). For the above example, the answer should be 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))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.