Skip to main content

list manipulation - Map works but Thread doesn't


This question may be trivial, but I can't get past it for the life of me.


I have $n$ matrices of dimension $p_i \times N_i$, with $i$ indexing the $n$-set. I also have $n$ vectors of the appropriate length.


I'm looking to create a list of the inner products. This works (obviously):


MapThread[Dot[#1,#2]&,{nmats,nvecs}]

The problem comes in when I pass in lists of nmats. That is, I have $C$ copies of nmats stored in cnmats and want to collect the above for each. For some reason Mapping works,


MapThread[Dot[#1,#2]&,{#,nvecs}]&/@cnmats

but Threading doesnt



Thread[MapThread[Dot[#1,#2]&,{#,nvecs}]&[cnmats]]

Replacing MapThread with Table moves the error to Dot: Nonrectangular tensor encountered.


The error returned is:


Incompatible dimensions of objects at positions {2, 1} and {2, 2} of (MapThread expression);
dimensions are n and C

$C$ and $N_i$ are $O(10^5)$, $p$ is $O(1)$, so I favor Thread for the speed advantage.


Why can't I thread here? How can I implement this differently to benefit from threading?




Comments