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.

2 Answers

1
Carles Mitjans On

Try this:

sum(v1[x] <= v2[x] <= v3[x] for x in range(3))
0
T. Kau On

If the v1, v2, and so on arenumpy.arrays you can do

np.sum(np.logical_and(v1<v2, v2<v3))