compute the total number of elements in the array size for in dimensions assert "dimensions must be size * create the - array to store the elements self _elements arraysize create - array to store the equation factors self _factors arraylen(dimensionsself _computefactors(returns the number of dimensions in the array def numdimsself )return len(self _dimsreturns the length of the given dimension def lengthselfdim )assert dim > and dim len(self _dims),"dimension component out of range return self _dims[dim clears the array by setting all elements to the given value def clearselfvalue )self _elements clearvalue returns the contents of element (i_ i_ i_ndef __getitem__selfndxtuple )assert len(ndxtuple=self numdims()"invalid of array subscripts index self _computeindexndxtuple assert index is not none"array subscript out of range return self _elements[indexsets the contents of element (i_ i_ i_ndef __setitem__selfndxtuplevalue )assert len(ndxtuple=self numdims()"invalid of array subscripts index self _computeindexndxtuple assert index is not none"array subscript out of range self _elements[indexvalue computes the - array offset for element (i_ i_ i_nusing the equation i_ f_ i_ f_ i_n f_n def _computeindexselfidx )offset for in rangelen(idx)make sure the index components are within the legal range if idx[jself _dims[jreturn none else sum the product of i_j f_j offset +idx[jself _factors[jreturn offset computes the factor values used in the index equation def _computefactorsself )