gpt4 book ai didi

python - 如何检查一个值是否属于 NumPy 类型?

转载 作者:太空宇宙 更新时间:2023-11-04 03:42:53 26 4
gpt4 key购买 nike

假设您有一个值,它可能是也可能不是 NumPy 数据类型之一。您将如何编写一个函数来检查是哪种情况?

def is_numpy(value):
# how to code?

最佳答案

我发现 works 的一种方式被 Mike T 在他对 Converting numpy dtypes to native python types 的回答中使用了:

def is_numpy(value):
return hasattr(value, 'dtype')

我不确定这是否是首选方法,但它相对简单明了。

关于python - 如何检查一个值是否属于 NumPy 类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25432523/

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