General matrix multiplication for ndarrays