我想在现有的 3-D 矩阵中添加一层、一行和一列,而不丢失矩阵的原始信息
import numpy as np
tensor = np.zeros((len(subjects), len(properties) , len(objects)))
#subjects are 4, properties are 5 and objects are 7 in my case.
print(tensor.shape)
(4, 5, 7)
所以我需要在更多的楼层、行和列上添加一个,这样它将给出以下输出
so it will give me
print(tensor.shape)
(5,6,8)
最佳答案
numpy.pad是你的 friend 。
>>> tensor = np.pad(tensor, (0,1), 'constant')
>>> tensor.shape
(5,6,8)
关于python - 如何向包含数据的现有数组添加一层、一行和一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57486747/