I have a list of matrices as follows:
myarrlist = [array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), array([[10, 20, 30],40, 50, 60],[70, 80, 90]])]
and,
sum(myarrlist)/float(len(myarrlist))
gave me the following result (which is what I require: result of matrix addition is a matrix)
array([[ 5.5, 11. , 16.5],[ 22. , 27.5, 33. ],[ 38.5, 44. , 49.5]])
But, when I gave
from numpy import *
for using dot() function for matrix multiplication, sum() function no longer gives a matrix as result but a single value (adding all elements). I am new to python and I am guessing sum() from numpy overrides the call to python built-in sum().
I am trying to add the matrices in the list without loops and find built-in sum() suitable for that. Is it possible to use python sum() and still use other features of numpy?
from numpy import dotfor example.import numpy as np, usenp.array,np.<function>for all numpy functions and thensumfor inbuilt. (Note:np.sum(myarrlist, axis=0)will do as you request - seehelp(np.sum): numpy seesmyarrlistas a 3D matrix so you have to tell it you only want to sum along axis0).dot()method that does what you'd expect :)