Comparison to `None` will result in an elementwise object

后端 未结 1 1364
予麋鹿
予麋鹿 2020-12-15 03:56

Apparantly it will (in the \'future\') not be possible anymore to use the following:

import numpy as np
np.array([0,1,2]) == None
> False
> FutureWarni         


        
相关标签:
1条回答
  • 2020-12-15 04:18

    You are looking for is:

    if a is None:
        a = something else
    

    The problem is that, by using the == operator, if the input element a is a numpy array, numpy will try to perform an element wise comparison and tell you that you cannot compare it.

    For a a numpy array, a == None gives error, np.all(a == None) doesn't (but does not do what you expect). Instead a is None will work regardless the data type of a.

    0 讨论(0)
提交回复
热议问题