初始化2D数组时发生TypeError吗?

时间:2019-07-09 14:59:13

标签: python arrays types typeerror

我想制作一个2d数组,其中包含另一个2d数组的标准化值。但是,在遵循其他教程/建议之后,我的函数返回TypeError。

我认为我使用的任何变量都不是类型,我已经更改了变量名,但无济于事。

def normalize(oldArray): #makes all vectors a ratio of the largest magnitude vector 
maxMagnitude = 0
row, column = len(oldArray), len(oldArray[0]) #Gets the Height and Width of Array for conversion
normalized = [[0 for x in range(column)] for y in range[row]] #Initializes the return array as empty
for x in range(len(oldArray)): #searches for maximum magnitude
    magnitude = math.sqrt(oldArray[x][0] ^ 2 + (oldArray[x][1] ^ 2) + (oldArray[x][2] ^ 2))    
    if magnitude > maxMagnitude:
        maxMagnitude = magnitude
for x in range(len(oldArray)): #converts all values into ratio of maximum magnitude
    magnitude = math.sqrt(oldArray[x][0] ^ 2 + (oldArray[x][1] ^ 2) + (oldArray[x][2] ^ 2))    
    ratio = magnitude / maxMagnitude
    normalized[x][0] = ratio
    normalized[x][1] = ratio
    normalized[x][2] = ratio 
return normalized 

错误消息:

newArray = [[0 for x in range(c)] for y in range[r]] #Initializes the return array as empty TypeError: 'type' object is not subscriptable

0 个答案:

没有答案