numpy.array boolean to binary?

前端 未结 2 2123
猫巷女王i
猫巷女王i 2021-02-13 00:29

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:56

    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) ;
    

提交回复
热议问题