In [188]:
a = np.random.randn(100,5)
b = np.random.randn(100)
c = np.minimum(a,b)
-
ValueError Traceback (most recent call last)
<ipython-input-188-f59fe6dbb41e> in <module>()
1 a = np.random.randn(100,5)
2 b = np.random.randn(100)
> 3 c = np.minimum(a,b)
ValueError: operands could not be broadcast together with shapes (100,5) (100,)
这可能不是最有效的方法,但它可以保持列顺序。您只需将
dataframe
和series
转换回numpy
数组来执行minimum
操作,将其转换回dataframe
。例如:我不清楚你在这里要做什么,因为在纽比,它不会工作,因为形状不能被广播:
如果尺寸已交换,则可以:
^{pr2}$因此,对于大熊猫来说,以下方法是可行的:
因此,您需要转置df(如果需要的话)以便广播工作,然后序列需要平坦化为一维数组,在本例中可以通过调用
.values
属性来完成相关问题 更多 >
编程相关推荐