A question about numpy

Paulo da Silva p_s_d_a_s_i_l_v_a_ns at netcabo.pt
Wed Apr 15 00:41:56 CEST 2015


I am new to numpy ...

Supposing I have 2 vectors v1 and v2 and a value (constant) k.
I want to build a vector r with all values of v1 greater than k and the
others from v2.

I found 2 ways, but not sure if they are the best solution:

1.
r1=v1.copy()
r2=v2.copy()
r1[r1<k]=0
r2[r2>=k]=0
r=r1+r2

2.
r=v1*(v1>=k)+v2*(v2<k)

Are there any better sols.?

Thanks for help/comments.



More information about the Python-list mailing list