How to identify numpy types in python?

前端 未结 6 761
生来不讨喜
生来不讨喜 2020-12-23 09:02

How can one reliably determine if an object has a numpy type?

I realize that this question goes against the philosophy of duck typing, but idea is to make sure a fun

6条回答
  •  一整个雨季
    2020-12-23 09:36

    The solution I've come up with is:

    isinstance(y, (np.ndarray, np.generic) )
    

    However, it's not 100% clear that all numpy types are guaranteed to be either np.ndarray or np.generic, and this probably isn't version robust.

提交回复
热议问题