1
我旨在防止數組中的負向索引。TypeError:未找到必需的參數__getitem__ numpy
import numpy as np
class Myarray (np.ndarray):
def __getitem__(self,n):
if n<0:
raise IndexError("...")
return np.ndarray.__getitem__(self,n)
class Items(Myarray):
def __init__(self):
self.load_tab()
class Item_I(Items):
def load_tab(self):
self.tab=np.load("file.txt")
a=Item_I()
當我創建一個實例我得到了一個錯誤:
in <module>
a=Item_I()
TypeError: Required argument 'shape' (pos 1) not found