Message Boards Message Boards

0
|
864 Views
|
0 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Thread error: Objects of unequal length cannot be combined

Posted 1 year ago

I try to generate a larger block diagonal matrix using several matrices, as shown below:

In[312]:= 
blockArray[mat_] := 
 SparseArray[
  Tuples[Range@# - {1, 0, 0}] . {Rest@#, {1, 0}, {0, 1}} &@
    Dimensions@mat -> Flatten@mat]
matrices = {RandomReal[1, {2, 2}], {{1}}}
blockArray[matrices] // Normal

Out[313]= {{{0.967425, 0.935199}, {0.592125, 0.365}}, {{1}}}

During evaluation of In[312]:= Thread::tdlen: Objects of unequal length in {{1,2}}+{-1,0,0} cannot be combined.

During evaluation of In[312]:= Dot::rect: Nonrectangular tensor encountered.

During evaluation of In[312]:= SparseArray::pos: The left-hand side of {{0,1},{1,2},{1,2}}.{{},{1,0},{0,1}}->{0.967425,0.935199,0.592125,0.365,1} in {{{0,1},{1,2},{1,2}}.{{},{1,0},{0,1}}->{0.967425,0.935199,0.592125,0.365,1}} is not a position or pattern that will match a position.

Out[314]= SparseArray[{{0, 1}, {1, 2}, {1, 2}} . {{}, {1, 0}, {0, 
     1}} -> {0.967425, 0.935199, 0.592125, 0.365, 1}]

I want to adjust the above method so that it can also accept a number as an argument. Any tips for achieving this goal?

Regards, Zhao

POSTED BY: Hongyi Zhao
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract