numpy.array boolean to binary?

前端 未结 2 1258
Happy的楠姐
Happy的楠姐 2021-02-13 00:23

I am trying to rewrite a matlab code in python27. There is a matlab line as follows:

vector_C = vector_A > vector_B;

If I try to write this

2条回答
  •  不要未来只要你来
    2021-02-13 00:34

    You can force numpy to store the elements as integers. It treats 0 as false and 1 as true.

    import numpy
    
    vector_C = numpy.array( vector_A > vector_B, dtype=int) ;
    

提交回复
热议问题