[英]Why can't __array_function__ be called from an instance of an np.ndarray?
我正在嘗試按照numpy 的指南編寫自定義數組容器,但我不明白為什么以下代碼總是返回NotImplemented
。
import numpy as np
a = np.array([1])
shape = (2, 2)
a.__array_function__(func=np.broadcast_to, types=(np.ndarray, type(shape)), args=(a, shape), kwargs={})
Out[5]: NotImplemented
即使正常方法顯然有效
np.broadcast_to(a, shape)
Out[6]:
array([[1, 1],
[1, 1]])
function np.broacast_to
只是一個例子, np.reshape
也有同樣的問題。
有誰知道我的錯誤是什么?
types
只應該包含實際實現__array_function__
的類型。 type(shape)
沒有實現__array_function__
,所以它不應該在types
中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.