允许与numpy兼容的数组结构的下游互兼容的包
arrayish的Python项目详细描述
用于与numpy兼容的数组的下游兼容性的库。
用法
对于替代阵列实现
importnumpyasnpimportarrayishasaiclassCustomArray(object):"""Your custom ``ndarray`` compatible implementation."""passdefdot(a,b,out=None)""" Your custom implementation of ``np.dot``. """pass# Between your own arraysai.dot.add((CustomArray,CustomArray),dot)# With Numpy Arrays, if you'd like. Can also pass another functionai.dot.add((np.ndarray,CustomArray),dot)ai.dot.add((CustomArray,np.ndarray),dot)
对于愿意支持替代阵列的下游库
importarrayishasaiimportnumpyasnp# Instead of this:np.dot(a,b)# Do this:ai.dot(a,b)