Python isinstance和type
作者:
斐硕人 | 来源:发表于
2021-08-09 18:05 被阅读0次
问题
如何判断变量是不是None或者numpy数组
解决
Python 中有 isinstance
和 type
两个函数
np.array 的类型为 np.ndarray
nonetype 值为 None

例子
其他
为什么不用==判断None呢?
在LSTM首节点判断时,使用==
在首节点之后,也就是变量变为numpy数组之后,会一直报错让使用all()
或者any()
去判断内部元素,而使用is
不会报错。
使用all()
或者any()
时在首节点为None时又会报错。
原因还没查
参考
- Python3 isinstance() 函数 - 菜鸡一枚 - 博客园 (cnblogs.com)
- python: how to identify if a variable is an array or a scalar - Stack Overflow
- Python判断 NoneType数据类型_fu6543210的博客-CSDN博客
- value - python isinstance numpy array - Code Examples (code-examples.net)
本文标题:Python isinstance和type
本文链接:https://www.haomeiwen.com/subject/wsazvltx.html
网友评论