I am using Numpy to store data into matrices. Coming from R background, there has been an extremely simple way to apply a function over row/columns or both of a matrix.
Pandas is very useful for this. For instance, DataFrame.apply() and groupby's apply() should help you.