我想知道是否有更有效/Pythonic 的方法来添加多个 numpy 数组(2D)而不是:
def sum_multiple_arrays(list_of_arrays):
a = np.zeros(shape=list_of_arrays[0].shape) #initialize array of 0s
for array in list_of_arrays:
a += array
return a
Run Code Online (Sandbox Code Playgroud)
Ps:我知道, np.add()但它只适用于 2 个数组。
是否可以重塑 np.array() 并且在新形状不一致的情况下,用 NaN 填充空白空间?
前任:
arr = np.array([1,2,3,4,5,6])
Run Code Online (Sandbox Code Playgroud)
目标,例如 2x4 矩阵:
[1 2 3 4]
[5 6 NaN NaN]
Run Code Online (Sandbox Code Playgroud)
我需要这个来绕过错误: ValueError: cannot reshape array of size 6 into shape (2,4)
谢谢,
我有一个矩阵x,其3 x 3维度和向量w是3,:
x = np.array([[1, 2, 1],
[3, 2 ,1],
[1, 2, 2]])
w = np.array([0.3, 0.4, 0.3])
Run Code Online (Sandbox Code Playgroud)
我需要生成另一个向量y,该向量对 x. 的每一列x由 中的相应值加权w。像这样的东西:
for y[0],它应该寻找X[0] => [1, 2, 1]
对w按其在 X 中的值分组的列的权重 (in )求和:
0.3 + 0.3 = 0.6我见过一些使用两种不同的实验,StandardScaler如下所示:
scaler_1 = StandardScaler().fit(X_train)
train_sc = scaler_1.transform(X_train)
scaler_2 = StandardScaler().fit(X_test)
test_sc = scaler_2.fit(X_test)
Run Code Online (Sandbox Code Playgroud)
我知道人们不应该对混合训练/测试数据的分类器产生偏见,但我想知道另一种情况是否正确:
# X_all represents X feature vector before splitting (train + test)
X_scaled = StandardScaler().fit_transform(X_all)
X_train, y_train, X_test, y_test = train_test_split(X_scaled,y_all)
Run Code Online (Sandbox Code Playgroud)
另外,我想知道这个案例如何延伸到KFold交叉验证。