第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

如何修復(fù) AttributeError:“Matrix”對象沒有“clear”屬性?

如何修復(fù) AttributeError:“Matrix”對象沒有“clear”屬性?

慕勒3428872 2022-06-22 18:41:57
我正在嘗試創(chuàng)建一個(gè) Matrix 類。但是,當(dāng)我創(chuàng)建它時(shí)它會給我?guī)礤e(cuò)誤。我試圖刪除 self._theGrid.clear(0) 但矩陣將被初始化為 None 而不是 0。from array_ import Array2Dclass Matrix :    # Creates a matrix of size numRows x numClos initialized to 0.    def __init__(self, numRows, numCols):        self._theGrid = Array2D(numRows, numCols)        self._theGrid.clear(0)    ....在我創(chuàng)建的模塊中。我正在使用以下模塊來創(chuàng)建矩陣。# Implement the Array ADT using the array capabilities of the ctypes moduleimport ctypesclass Array:     # Create array with the size elements    def __init__(self, size):        assert size > 0, "Array size must be > 0"        self._size = size         # Create the array structure using ctypes module        PyArrayType = ctypes.py_object * size        self._elements = PyArrayType()         # Initialize each element        self.clear(None)     # Returns the size of the array    def __len__(self):        return self._size     # Get the contents of the index element    def __getitem__(self, index):        assert index >= 0 and index < len(self), "Array subscripts out of range"        return self._elements[index]      # Puts the value in the array element at index position.    def __setitem__(self, index, value):        assert index >= 0 and index < len(self), "Array subscripts out of range"        self._elements[index] = value     # Clear the array by setting each element to the given value.    def clear (self, value):        for i in range(len(self)):            self._elements[i] = value     # Returns the array's ierator for transversing the elements.    def __iter__(self):        return _ArrayIterator( self._elements )# An iterator for the Array ADT.class _ArrayIterator:    def __init__(self, theArray):        self._arrayRef = theArray        self._curNdx = 0    def __iter__(self):        return self我無法得到所有矩陣條目都初始化為 0 的結(jié)果。第 8 行,在init self._theGrid.clear(0)第 77 行,在 clear row.clear(value) 中AttributeError:“矩陣”對象沒有屬性“清除”我無法用 x = Matrix(2,3) 初始化矩陣。
查看完整描述

1 回答

?
呼喚遠(yuǎn)方

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超11個(gè)贊

您似乎在這里迭代數(shù)組的長度:


...

def clear( self, value ):

    for row in range( self.numRows() ):  # row is 0, 1, 2, ...  

        row.clear( value )               # int has no method or attribute with name "clear" -> error is raised

...

嘗試遍歷數(shù)組:


...

def clear( self, value ):

    for row in self._theRows:

        row.clear( value ) 

...


查看完整回答
反對 回復(fù) 2022-06-22
  • 1 回答
  • 0 關(guān)注
  • 106 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號