获取阵列列表中最大的一列

时间:2014-09-30 21:04:05

标签: python arrays numpy dictionary max

如果我有ordered dictionarynumpy数组

from collections import OrderedDict

>>> bias
OrderedDict([('bias_0.0', array([[ -4.76624398e-04,   4.49229230e-03,   1.70000000e+01],
       [ -1.55963349e-03,   1.43121798e-03,   1.80000000e+01],
       [  1.83762370e-03,   1.15303340e-03,   1.90000000e+01],
       [  3.11141924e-03,   7.94052356e-04,   2.00000000e+01],
       [ -1.45957877e-04,   9.43913508e-04,   2.10000000e+01],
       [ -2.81545419e-04,   9.63629400e-04,   2.20000000e+01],
       [  8.18959167e-04,   9.94954147e-04,   2.30000000e+01],
       [  2.83641949e-03,   1.30510580e-03,   2.40000000e+01]])), ('bias_0.5', array([[ -4.76624398e-04,   4.49229230e-03,   1.70000000e+01],
       [ -1.55963349e-03,   1.43121798e-03,   1.80000000e+01],
       [  1.83762370e-03,   1.15303340e-03,   1.90000000e+01],
       [  3.11141924e-03,   7.94052356e-04,   2.00000000e+01],
       [ -1.45957877e-04,   9.43913508e-04,   2.10000000e+01],
       [ -2.37881094e-04,   9.59085284e-04,   2.20000000e+01],
       [  3.66215090e-03,   9.91373349e-04,   2.30000000e+01],
       [  1.34585904e-02,   1.43382398e-03,   2.40000000e+01]])), ('bias_0.7', array([[ -4.76624398e-04,   4.49229230e-03,   1.70000000e+01],
       [ -1.55963349e-03,   1.43121798e-03,   1.80000000e+01],
       [  1.83762370e-03,   1.15303340e-03,   1.90000000e+01],
       [  3.11138346e-03,   7.94066088e-04,   2.00000000e+01],
       [ -1.42918871e-04,   9.43977120e-04,   2.10000000e+01],
       [  1.22558682e-04,   9.78267596e-04,   2.20000000e+01],
       [  7.97667211e-03,   1.05694380e-03,   2.30000000e+01],
       [  1.72989414e-02,   1.60985477e-03,   2.40000000e+01]])), ('bias_0.9', array([[ -4.76624398e-04,   4.49229230e-03,   1.70000000e+01],
       [ -1.55963349e-03,   1.43121798e-03,   1.80000000e+01],
       [  1.83762370e-03,   1.15303340e-03,   1.90000000e+01],
       [  3.11163249e-03,   7.93727126e-04,   2.00000000e+01],
       [ -1.59545890e-05,   9.47506839e-04,   2.10000000e+01],
       [  3.09800829e-03,   9.76612289e-04,   2.20000000e+01],
       [  8.85488891e-03,   8.91245114e-04,   2.30000000e+01],
       [  8.39106167e-03,   9.21750885e-03,   2.40000000e+01]])), ('bias_0.95', array([[ -4.76624398e-04,   4.49229230e-03,   1.70000000e+01],
       [ -1.55963349e-03,   1.43121798e-03,   1.80000000e+01],
       [  1.83848596e-03,   1.15319035e-03,   1.90000000e+01],
       [  3.11342300e-03,   7.93791443e-04,   2.00000000e+01],
       [  4.05623641e-04,   9.67667341e-04,   2.10000000e+01],
       [  1.13983053e-03,   8.23258801e-04,   2.20000000e+01],
       [ -4.42620841e-03,   1.09573777e-03,   2.30000000e+01],
       [ -1.98968147e-03,   1.03812656e-02,   2.40000000e+01]]))])

如何获得所有数组中第一列的最大值?

2 个答案:

答案 0 :(得分:3)

您可以使用列表推导来列出bias中每个数组的第一列中的最大值:

>>> [np.max(arr[:,0]) for arr in bias.values()]
[0.0031114192400000002,
 0.0134585904,
 0.0172989414,
 0.0088548889100000007,
 0.0031134230000000001]

如果您需要从此最大值列表中找到最大值,则可以使用内置函数max

答案 1 :(得分:0)

我假设你想要每个数组一个最大值,仍然归因于与原始OrderedDict中相同的键。你可能会说

maximumValues = OrderedDict( [ ( eachKey, eachArray[:,0].max() ) for eachKey, eachArray in bias.items() ] )