gpt4 book ai didi

python - numpy.minimum() 的返回类型?

转载 作者:太空宇宙 更新时间:2023-11-03 13:23:31 32 4
gpt4 key购买 nike

当我在 bool 数组上使用 numpy 函数 minimum()maximum() 时,结果类型打印为 numpy.int32。但是,与 numpy.int32 类型的比较失败(即使在转换之后)。这是错误吗?

g = np.ones((5, 5), dtype = np.bool)
h = np.maximum(g, 4)
i = np.int32(h)

print 'type of g ', g.dtype.type # prints <type 'numpy.bool_'>
print 'type of h ', h.dtype.type # prints <type 'numpy.int32'>
print 'type of i ', i.dtype.type # prints <type 'numpy.int32'>

print h.dtype.type == i.dtype.type # prints True
print h.dtype.type == np.int32 # prints False
print i.dtype.type == np.int32 # prints False
print i.dtype.type == np.bool_ # prints False

最佳答案

在我看来很正常。使用 np.maximum 返回 g4 的最大值,即 4 (True == 1)。你得到一个全是四的矩阵,整数类型。

如果您使用此语法进行类型比较,它们会起作用:h.dtype.type == np.dtype(np.int32) 或更简单的 h.dtype == np .int32.

关于python - numpy.minimum() 的返回类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5582760/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com