小编eca*_*t33的帖子

python type()和isinstance()无法识别类的实例

isinstance(object, classinfo) 无法识别类的实例。

我打印type(object)了该类并验证了它们是否是相同类型。他们俩都印出了完全一样的东西,但是当我尝试type(object) == class返回时False。

这是该类的代码:

class Convolute(object):
    def __init__(self, channels, filter_shape, pool_shape, pool_type, stride_length=1):
        self.channels = channels
        self.filter_shape = filter_shape
        self.filters = [np.random.randn(filter_shape[0], filter_shape[1]) for i in range(channels)]
        self.biases = [random.random() for i in range (channels)]
        self.stride_length = stride_length
        self.pool_shape = pool_shape
        self.pool_type = pool_type
Run Code Online (Sandbox Code Playgroud)

这是该类的实例:

con1 = n.Convolute(3, (4, 4), (4, 4), 0)
Run Code Online (Sandbox Code Playgroud)

这是当我尝试验证它们是否相同类型时在python shell中的输出:

>>> import network as n
>>> con1 = n.Convolute(3, (4, 4), (4, 4), 0)
>>> type(con1) …
Run Code Online (Sandbox Code Playgroud)

python isinstance

5
推荐指数
0
解决办法
198
查看次数

标签 统计

isinstance ×1

python ×1