我想将大小为508x12的numpy数组A插入另一个大小为508x13的numpy数组B中,从而得到大小为508x25的数组。但这是问题,我不只是想要合并它们,而是将数组插入一个特定的列位置c。
我该怎么做?,我尝试过:
C = np.insert(B,c,A,axis=1)
只需像@brezniczky建议的那样拆分连接。或者,使用hstack:
import numpy as np
a = np.ones((508,12))
b = np.zeros((508,13))
col = 3
final = np.hstack((b[:,0:col],a,b[:,col:]))
print(final[0])
[0。 0. 0. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0。 0。]
在这种情况下,hstack和与axis = 1的串联是相同的,我只是更喜欢hstack以提高可读性