问题描述:

If I have an ordered dictionary of numpy arrays

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]]))])

How could I get the maximum value of the first column in the all arrays?

网友答案:

You could use list comprehension to make a list of the maximum value in the first column of each array in bias:

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

If you need to find the maximum from this list of maximums, you can use the built-in function max.

网友答案:

I'll assume you want one maximum value per array, still attributed to the same keys as in the original OrderedDict. You might say

maximumValues = OrderedDict( [ ( eachKey, eachArray[:,0].max() ) for eachKey, eachArray in bias.items() ] )
相关阅读:
Top