0
我一直在遇到TypeError:list索引必須是整數,而不是元組。然而,我無法弄清楚如何解決這個問題,因爲我顯然誤解了這個元組的位置(甚至沒有意識到我會理解這個元素)。我的索引和傳遞的值不應該是整數嗎?包含元組的數組列表(?)
def videoVolume(images):
""" Create a video volume from the image list.
Note: Simple function to convert a list to a 4D numpy array.
Args:
images (list): A list of frames. Each element of the list contains a
numpy array of a colored image. You may assume that each
frame has the same shape, (rows, cols, 3).
Returns:
output (numpy.ndarray): A 4D numpy array. This array should have
dimensions (num_frames, rows, cols, 3) and
dtype np.uint8.
"""
output = np.zeros((len(images), images[0].shape[0], images[0].shape[1],
images[0].shape[2]), dtype=np.uint8)
# WRITE YOUR CODE HERE.
for x in range(len(images)):
output[:,:,:,:] = [x, images[x,:,3], images[:,x,3], 3]
# END OF FUNCTION.
return output
那是完整的代碼?還有什麼是追溯? –
這是完整的代碼。 回溯: 回溯(最近通話最後一個): 文件 「assignment_test.py」,線路377,在 如果不是test_videoVolume(): 文件 「assignment9_test.py」,行73,在test_videoV usr_out =分配.videoVolume(img_list) 輸出[:,:,:,:] = [x,images [x,:,3]文件「C:\ Users \ user \ Documents \ assign.py」,第53行,videoVolume ,圖像[:,x,3 TypeError:列表索引必須是整數,而不是元組 –
Runner
'images [x,:,3]'是image [(x,:,3)]的縮寫。 '[]'裏面的東西是一個「元組」。 'np.array'可以處理那種索引,普通列表不能。 – hpaulj