import numpy as np
# Create your (10, 5) array (10 samples with 5 features)
array_10x5 = np.random.rand(10, 5)
# Create your single sample (1, 5)
single_sample = np.random.rand(1, 5)
# Multiply the entire (10, 5) array with the single sample using broadcasting
result = np.sum(array_10x5 * single_sample, axis=1)
# result is now a (10,) array where each element corresponds to the sum of the
element-wise products
print(result)
2条答案
按热度按时间z0qdvdin1#
vaj7vani2#
我写这段代码是基于我对你所说的理解。这是你想要的输出吗?