有没有numpy
办法从字符串创建 dtypes?numpy.dtype()
几乎是我需要的,但它会产生不一致:
import numpy as np
dtype1 = np.dtype('float32')
dtype2 = np.float32
# This works (prints "same")
if dtype1 == dtype2:
print("same")
# I want the code in the line below to produce a set with one item
# However, the resulting set is: {dtype('float32'), <class 'numpy.float32'>}
dtypes = {dtype1, dtype2}
# One way to fix the above is to write the following, but this is ugly
dtypes = {np.empty(1, dtype1).dtype, np.empty(1, dtype2).dtype}
有没有一种优雅的方法来解决上述问题?
谢谢