Use fold in some matrix operators