我想向现有数据多维数据集中添加另一个“切片”数据:
import numpy as np
a = np.array([[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]], [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]])
print(a.shape) # (2, 3, 4)
b = np.array([[7, 7, 7], [8, 8, 8]])
print(b.shape) # (2, 3)
c = np.concatenate([a, b], axis=2) # ValueError: all the input arrays must have same number of dimensions
print(c.shape) # wanted result: (2, 3, 5)
因此,我基本上想通过将最后一个尺寸扩展为2x3x5将2x3数组添加到2x3x4数组中。值错误对我来说不太有意义,因为数组的形状不能相同?我在这里做什么错了?
答案 0 :(得分:4)
在onParentClick(index) {
let items = this.items;
Observable.of(items).subscribe((items: any) => { //<======= here you can set any
this.el.nativeElement.dispatchEvent(new CustomEvent(items[index].eventName, {}));
console.log( items[index].eventName );
});
}
的末尾添加一个新轴,然后进行串联-
b
所以,对于给定的样本-
np.concatenate((a, b[...,None]), axis=2)