python - Sum All elements of each array in an array of arrays -
i have dictionary:
import numpy np dict={'w1': np.array([[ 1.62434536, -0.61175641, -0.52817175], [-1.07296862, 0.86540763, -2.3015387 ]]), 'b1': np.array([[ 1.74481176], [-0.7612069 ]]), 'w2': np.array([[ 0.3190391 , -0.24937038], [ 1.46210794, -2.06014071], [-0.3224172 , -0.38405435]]), 'b2': np.array([[ 1.13376944], [-1.09989127], [-0.17242821]]), 'w3': np.array([[-0.87785842, 0.04221375, 0.58281521]]), 'b3': np.array([[-1.10061918]])}
i need sum elements of w1, w2, w3 after squared them, each 1 @ time of three.
i used extract list keys w(i)
l=[v k, v in dict.items() if 'w' in k]
how sum of squared elements in each array? when taken each array separately do:
np.sum(np.square(l[0]) 10.4889815722 l[0]
i don't know though how sum them in 1 shot
i'm not sure got you, here's think you're looking for:
>>> import numpy np >>> data = [np.array([1.62434536, -0.61175641, -0.52817175]), np.array([-1.07296862, 0.86540763, -2.3015387])] >>> [np.sum(arr) arr in data] [0.48441719999999999, -2.5090996900000002]
Comments
Post a Comment