python - NumPy 的 : Check array for string data type

标签 python arrays string

如何确定 Numpy 数组是否包含字符串?数组a

a = np.array('hi world')

具有数据类型dtype('|S8'),其中8指的是字符串中的字符数。

我不明白正则表达式(例如 re.match('\|S\d+', a.dtype))在这里如何工作,因为数据类型不仅仅是 '|S8'.

最佳答案

a.dtype.char == 'S'

a.dtype.type is np.string_

参见 NumPy docs, Data type objects, Attributes .

关于python - NumPy 的 : Check array for string data type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10790312/

相关文章:

Python - 正则表达式 - 在单词之前拆分字符串

python - 非常大的数字的最大精度

python - python中的正则表达式多次删除字符和数字的孤立出现

python - 使用 Cython 循环 Numpy 数组

javascript - 将字符串中的字母按顺序大写并创建一个数组来存储

java - 字符串文字池的工作原理

python - 等到 QtWidgets.QMainWindow 关闭后再继续

c++ - 如何编写模板来检查给定值是否在数组中

python - 如何在python字符串中找到相反的字符?

javascript - 如何从数组 [JS] 中删除换行字符串