TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType'
程序员文章站
2022-03-05 12:20:41
...
当你使用spark udf时,进行如下操作
@udf(ArrayType(DoubleType()))
def listdivision(alist,blist):
if (np.array(blist).sum() is None)|(np.array(alist).sum() is None):
return None
else:
result=[]
label = np.array(blist)==0
result = np.array(alist)/np.array(blist)
result[label] = 1
return result
其核心就是np.array的除法,当array内部存在array([None])时就会造成这样的报错
所以需要使用np.array(blist).sum() is None进行判断
推荐阅读
-
TensorFlow2前向传播碰到的unsupported operand type(s) for *: 'float' and 'NoneType'问题
-
小白入门常见报错:TypeError: unsupported operand type(s) for +: ‘int‘ and ‘str‘ 萌新踩雷!!!
-
Error: unsupported operand type(s) for +:´ dict´ and ´ dict´
-
Django项目debug--TypeError: unsupported operand type(s) for /: ‘str‘ and ‘str‘,分析与解决
-
TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType'
-
TypeError: unsupported operand type(s) for +: 'getset_descriptor' and 'int'
-
Django 错误 TypeError: unsupported operand type(s) for PosixPath and str
-
[机器学习实战-ch09]TypeError: unsupported operand type(s) for /: 'map' and 'int'