【问题标题】:How to add elements to a 3d array in python如何在python中将元素添加到3d数组
【发布时间】:2022-06-10 18:57:10
【问题描述】:

我在堆栈溢出时发现了这段代码,但我无法将它与 numpy 数组一起使用。谁能帮忙?

    # Define how large to make the object.
size = 3

# Build the three dimensional list.
memory = []
for x in range(0,size):
    memory.append([])
    for y in range(0,size):
        memory[x].append([])
        for z in range(0,size):
           memory[x][y].append(0) # Fill with zeros.

# Iterate through all values.
for x in range(0,size):
    for y in range(0,size):
        for z in range(0,size):
            print 'memory[' + str(x) + '][' + str(y) + '][' + str(z) + ']=' + str(memory[x][y][z])

# Example access.
print 'Example access:'
print 'memory[0][1][2]=' + str(memory[0][1][2])

【问题讨论】:

  • “我无法使用它”是什么意思。它会出错吗?如果是这样,你能发布错误吗?

标签: python numpy 3d append


猜你喜欢
  • 1970-01-01
  • 2013-03-05
  • 1970-01-01
  • 2010-10-19
  • 1970-01-01
  • 2021-09-16
  • 1970-01-01
  • 2015-05-14
  • 1970-01-01
相关资源
最近更新 更多