【发布时间】:2021-08-21 21:05:20
【问题描述】:
我希望能够在多维 numpy 数组中附加值并访问所述值。
例如:
import numpy as np
animal = np.array([[]])
mammal = ["monkey","dog","cat"]
amphibian = ["frog","toad","salamanders"]
aquatic = ["fish","eel","whale"]
list = [mammal, amphibian, aquatic]
for i in list
animal = np.append(animal, list[i])
animal = np.append(animal,bird[])
bird = np.append(bird,"eagle")
print(animal)
print(animal[2][2])
预期输出:
(["monkey","dog","cat"],
["frog","toad","salamanders"],
["fish","eel","whale"],
["eagle"])
"whale"
【问题讨论】:
-
您应该考虑使用列表列表而不是 numpy 数组,因为您的行大小不完全相同。
标签: python arrays numpy for-loop multidimensional-array