# Confused about Dimension Mismatch

I have the following code snip:

``````	a = Matrix(dR')
b = W
@show size(a),size(b)
@show typeof(a), typeof(b)
G = a*b
``````

This is the output/error I get:

``````(size(a), size(b)) = ((1, 5), (5, 4096))
(typeof(a), typeof(b)) = (Array{Float64,2}, Array{Float64,2})
ERROR: LoadError: DimensionMismatch("dimensions must match")
Stacktrace:
[1] promote_shape at .\indices.jl:154 [inlined]
[2] promote_shape at .\indices.jl:145 [inlined]
[3] -(::Array{Float64,1}, ::Array{Float64,1}) at .\arraymath.jl:38
``````

the sizes and types appear the same from the @show(), why is there a Dimension Mismatch?

Can you please post a code to generate your matrices?

Its a bit complicated for me to provide code to generate the matrices, these are the matrices if I print them out though:

``````a = [-218.83661398333524 -361.8123414207717 166.41607814303595 -85.62425321179961 -318.313315175026]
b = [0.035196156028309326 -1.587458181822493 -1.2440061809684893 -0.8354153009036861 0.1210112772934259 0.05144704961386813 0.011657254136179641 -1.1538078174451762 1.556573188912387 0.7565245743636987 0.7111734646189398 -0.6381983212188489 0.6274930085346317 -0.8751966931978585 -0.8629080488738717 -0.060723644382305035 1.7435286570899164 -1.2570794730641046 -1.1540226620642111 -0.11478180017733043 0.004402902651352532 -0.1789889253069637 -1.214401421974179 -1.128395843986053 0.3167517457303077 -0.7758254316291796 0.8087254427236087 1.9045836123364293 0.062136695755553424 0.6857843984695194 0.9198555860448454 -0.6708807369448297 0.5236160643706721 0.17519293520589435 0.7673037620715905 -1.6199836932042542 1.843777321767345 0.13063834740495192 -0.2989970318856526 0.9288652253910858 -0.30054156981390334 1.7604339359489227 -0.36132092842247143 -0.2482635744448893 -0.033266961846249055 0.07201783339826492 -1.7791104078766204 -0.805628445249317 1.3565890405092063 0.1712467685135568 0.25673077937518324 -0.4585302897691986 0.4328862659222567 -0.01322656648656051 -0.13195181606060424 -0.8228466552929878 -1.3806941391975278 -0.4404959877144972 -1.0778875374364347 0.31630187925467557 0.7672610075182886 1.2836860423682812 2.6513524491928777 0.7395508955038321 1.1212077135430167 -0.32580489155322606 2.114797425520045 1.1668065617171246 -0.0503937594959576 2.651434739835797 -1.0868975647222314 0.36398702357233315 2.5022934502759657 0.5764095256521305 -0.9313646223046019 -0.21408510785181237 -1.0685491320367173 0.7851752755576531 1.7684621409697314 0.6047048101137453 -0.38524180906355304 -0.5576808517004302 -0.9390129201592587 -1.3132355713791095 -0.79231878887735 0.6710243642686201 -0.27485405778038763 -0.22936077040118988 0.427434146258887 -0.19945029212967902 1.8789982061717057 0.02125918364489107 1.237679885442142 -0.606730865916931 -0.5733285199533853 0.6806163894198946 -1.7556521613126461 1.1832884274641629 1.65338028280467 -0.17773363836399803 0.9879511032069961 -0.00515046914711949 1.1247767318546742 0.7831267367151491 -0.8130652005138812 2.5407844207633072 0.35896342882468296 -0.8259747533830487 0.22623458004324676 -0.13665557977376858 -0.036562018347497824 0.27262892083368384 0.8966994451211232 -0.053694667001765145 1.0273182637780884 1.0805475814444483 0.2665981499661743 0.5234624901392826 -1.0353535347463818 -0.6283360472529199 0.869425162931424 -0.8188124858022103 -2.3176951154402694 -0.2613457308622065 0.4324320849749963 -1.0957545402238977 -0.9836748952915246 1.0203485141313964 1.6796819334422364 -0.7593141063624197 0.35638677142795494 -0.17518885411244361 -0.5896464192506169 0.19978116380772026 -0.7241992180232811 0.12074122474198207 0.5238615453769737 -0.5266855965686824 -0.08982050006362276 0.00786158054868468 -0.8453431504321003 0.5429228774980399 -0.03351487859397267 0.5127695537916325 -1.034976029437341 0.7922662905634398 1.005885914712144 0.2457266973425732 -1.0095718472658375 1.9547306765261114 0.01895804377451305 0.6326939688962212 0.4225876342248756 -0.05913343672531503 0.1607954114037867 -0.10801766965785643 0.44064683034291463 0.07405197474852887 1.4977272865809108 1.6205428169172462 -0.23264792937810805 -2.0280973683382157 -2.2080934403362704 -0.5879186871463542 0.023201883398743652 -0.13158184727639854 0.6172194008633385 -0.45441018406211653 0.3614028909826671 0.6081842716926622 -1.0437033115405194 -0.1644511594891565 -0.41951189638254727 1.9059870703679942 1.7096376861599292 0.6917451245723986 0.49375060272166305 -0.032558064762072 -1.760983706924265 1.9412212402129019 0.9852727065122315 0.5315078178062045 1.9197165371787723 -0.07726190803648621 0.03604588890858584 0.4447526336475197 -0.6285093306610324 1.1726661339913382 0.17225926855873433 1.0966702880195849 -0.9131912929191056 1.3725534703454223 -1.9504958828989776 -0.37399506983712627 2.0646923358843576 0.9120950357281663 -0.8946230829649753 -0.4479546745251826 -1.0643505342720618 -0.20688062897083218 -0.3464003183749474 1.2963006220289843 1.0471561499080126 -0.962395846229993 -0.3539263830626149 -2.1291906962897076 0.6295534887668485 -0.030289439266287178 -0.7730489623297165 -0.01408086953174934 1.996100377685018 1.2187504791631538 1.0195290786021 1.001503718731012 -0.17790450974009428 -0.5116027307437289 0.9305192435515491 -0.6034269982697265 -0.5573751559456233 0.7068107993095469 -0.5762758290672825 -0.37356879363156703 -0.025644563724435913 -0.09054792970902145 -0.7298497006798 -0.2157435324133032 0.24414095252477813 0.3618127900101962 -0.9015373747936013 0.3396207384647691 -2.2841492708605795 -1.1280243575052398 0.41119198555120584 -1.3253474940725607 1.0967020689312572 -0.4451240734485312 -0.5987195866115745 0.8965320507438772 0.8076545443046461 -0.04635989246899745 1.1554664978983802 0.8600741191211176 -0.29122991785413904 -0.41093311950189115 -0.31770823480298105 -0.04435825377953615 -0.6004006663495479 0.020467797110431507 -2.1086312953845248 -0.182479262392574 0.827628052952143 0.7341234790117356 0.08751297653771789 0.7586535355753432 -0.1043263214200902 0.5823521461873351 1.3657547427778565 0.31006220697343795 0.12341479211665828 0.6863865950306819 0.6760259773111209 0.3889794787508245 -0.7242327683076368 0.7834149807815572 0.5041957064341626 0.2339317342287022 0.44498362963789057 0.5367261415033417 -0.42003620203799275 0.8746919575083955 -1.5701760675467118 0.3518627652016436 -0.2416445802398441 0.5560438935231505 -0.2987868593469268 -1.812327419645237 0.014893850897800341 1.8094844261089522 -1.126750391214162 1.2769407554029293 -0.40438469850854963 0.3493131261660906 -0.4080948031539499 -0.12119691522998935 -1.316018783368165 -1.5762573017217083 -0.8674549794231095 -0.08661744567669011 0.5841674958802107 3.9821200177526457 -1.7073647605760043 0.6132229039622176 1.175569207237675 1.091869449412918 -1.5915738857412682 -0.4073142390360093 0.5615921696832394 0.4241349158788612 0.7181543667471291 -1.2351701485202884 -0.17277903194167832 0.17067465541695356 2.4415299672363155 -0.8429523729466952 0.7440663286706506 0.8100063196667101 -0.8626651645848127 -0.13670404998738678 0.5159069797831278 -0.5742257875869872 2.31552599312642 0.7152660007311334 0.5420147457023342 0.14399978514078937 1.0128378513076948 1.582539244972402 -1.8836791299430584 1.5572570731566435
0.00855419211131007 1.1847694560084256 -0.6972664837726615 -1.6168422641581495 0.4616621537593648 -0.2900225848651666
-0.34795820465201305 0.021327806774525372 0.10842054584443886 0.3969693094462848 0.7417448307128581 -0.5927403382118804 1.3957410109071382 2.0384595468916693 -1.0128195543994045 -0.84723817237989 -1.7506437383875255 -0.6020615794239239
0.8899626038959728 -1.913376289902818 -0.11568476663812734 -0.5927030160893584 -0.4557225391964676 2.0741405107801367
-0.38297967292408797 0.6461084411868944 1.5831320779083111 1.8390522562719893 0.5509327535437663 -0.8237107419959521 1.693494685531959 2.3979790517026487 0.5113597292875935 0.029076136120127594 0.8248237886112798 0.7142921167717702 0.5142116240688076 0.40405742600739847 -0.3635622497786376 -0.4766813615637044 -0.26869220324045606 -0.11041500678563212 -0.5083058710349017 0.16108229181208514 0.11754265473461102 -1.1241229264050796 -1.747326966078046 -0.4009131592795057
0.6840400507569905 0.8094395508949324 0.9130037981275276 -0.4969306726695889 -0.4150693534018847 -0.6866416257575007 -0.013762663128367164 -1.7378778888554087 -2.5887657353801914 0.36672135605119816 0.4974386142024514 -0.02363921949498225 0.7111665124136506 -0.15137481505419315 -1.0839473544904346 -1.791093756254836 -0.8744543563708591 -0.12548319988288636 0.22490291024875012 -0.12919203233795168 -0.06117298104844963 -0.7788326645318944 -0.28713533555659454 -0.2591206439526505 -0.7542880863366358 -0.7679765739909001 -1.0632440527064282 -0.16776161164877196 0.7984580382797294 -0.6540229866383115 -1.10012006734546 0.8667349514709278 -0.12660400670778663 0.6629137258056578 2.2037476555984 0.19458859123949818 0.3568726581502558 -0.5808692684809502 -0.3915419906646938 1.1222315776816072 0.07432265220114877 -1.086038750397314 -0.9465352051342693 1.7321514737999986 0.5630532748550576 -0.7967207454175894 0.8706889978370168 -1.4542345982395903 -1.0662773524697056 1.4902758419337911 -0.7471436879550932 -0.31283494637556397 -1.3892604370726198 0.7003524099496917 -0.1083978247973026 1.0528101084837505 0.02043302603706788 -0.14877615703081967 0.6959438799117258 -0.12837965615641023 1.3667227321312376 -0.022623442510175684 -1.13608088785974 1.4495536039662844 1.2876369217963344 -1.4568542230466626 -1.3888379418067356 0.29665194264027184 -1.9147368347625726 -0.04539798363086389 -0.9624123855323818 0.43482508358457944 0.07073602128490733 0.4300030566478173 -0.3228558652558481 -1.9590703046271092 0.008851201184369613 0.14808238154933973 0.9806522994858374 0.37388419854411215 0.1675326665270973 -0.6450276708718976 -0.7277585979527267 0.17200785034545785 1.3563606112287634 -0.8212342139805533 -0.431507734833745 0.4051686508612974 0.43585059707716595 -0.17654451274844374 -0.5793201610401837 0.08893634043455817 -0.00013097180092438927 -1.1748263690440106 -0.6888655729125507 -0.5309430135258357 0.8007929689506572 -0.8227027682277269 -0.05388061769764568 -2.252344950418696 -0.8473206247546758 0.5455101918741088 1.4952812217311477 0.8084706442598415 0.4357289061619406 0.29037325413588777 0.21573137800995026 0.5658588531568571 -0.9547224691533254 0.3845298527035188 -0.17811725581337995 -0.2863737844975909 1.0755134920336755 -0.9273095654270067 -1.1208142804102945 0.644229083965741 0.2825992557786974 -0.3016208284644199 1.4176748787425082 -0.014938982142432996 0.9415314012055879 0.6501018841525634 1.0236314376947104 0.5598808975240941 0.9753758740703418 0.6091673665343172 -1.0934453006273264 0.9505962226745324 -0.8567018692011561 -0.14078587940349666 1.232082869694779 1.389842020414105 0.6095444944357847 0.044970692890555386 0.28747339641556613 2.4083872412429193 -1.2881780959206484 -1.9246226530594797 -0.9993034616683173 -1.4167508854886286 -0.6415801492099944 0.3333185306407675 1.6484139662763315 0.30237141477905904 -0.20137244912227287 -0.2584670765520996 -0.552580982454267 0.9369551358545448 -0.32407424154864944 0.5988162798696354 1.2101962414483327 -0.4894108579836629 1.1994937719169347 0.7466709248913503 -0.09359137297357319 0.4807387187293089 0.4866842562790539 -0.6857182152752129 -0.24132869745011146 0.7767566418459095 -0.5941710973929413 1.192516311299241 -0.49424603912888526 -0.8756703180169705 -0.10420794659236066 1.2682172395333013 1.552393036566614 -0.7201801452869622 0.23186595220520395 0.19820817110690553 0.6794163899377523 -0.8360351006493086 0.9692021450441138 0.7302147939436319 -0.820346180413356 -0.5855747411202389 -0.13990421134748784 0.40711693602060633 -0.8159768180638913 -1.4143969121538962 -1.761202913932686 0.03570323455064869]
``````

I had to crop a big part of the b matrix to be able to send it, I don’t know if this helps though

Works for me:

``````julia> A=rand(Float64,5,1)
5×1 Array{Float64,2}:
0.2666400804573059
0.013809823633287754
0.02029482496653645
0.29355225061851464
0.4603132933757301

julia> a=Matrix(A')
1×5 Array{Float64,2}:
0.26664  0.0138098  0.0202948  0.293552  0.460313

julia> b=rand(Float64,5,4096)
5×4096 Array{Float64,2}:
0.153815   0.505066    0.0646491  0.477978  0.369202   0.66309   0.729988   …  0.0892927  0.878815  0.949698  0.0265556  0.158212  0.149216  0.0616651
0.597092   0.932327    0.93776    0.808967  0.100478   0.84697   0.459201      0.122894   0.333161  0.139795  0.529286   0.243743  0.770572  0.381471
0.0150179  0.593121    0.451872   0.827052  0.0205585  0.714262  0.918499      0.883573   0.915493  0.379174  0.923125   0.391509  0.579381  0.534099
0.623445   0.00796981  0.251201   0.75877   0.808532   0.228158  0.707497      0.713908   0.478814  0.730026  0.347308   0.761244  0.236447  0.596316
0.701516   0.783464    0.595651   0.669723  0.362712   0.96362   0.0317485     0.352988   0.483017  0.641315  0.422062   0.394783  0.676521  0.72048

julia> @show size(a),size(b)
(size(a), size(b)) = ((1, 5), (5, 4096))
((1, 5), (5, 4096))

julia> @show typeof(a), typeof(b)
(typeof(a), typeof(b)) = (Array{Float64,2}, Array{Float64,2})
(Array{Float64,2}, Array{Float64,2})

julia> a*b
1×4096 Array{Float64,2}:
0.555495  0.522562  0.387286  0.686426  0.504556  0.713542  0.441928  0.353138  …  0.415492  0.620404  0.77236  0.329358  0.458686  0.443008  0.539246

julia> versioninfo()
Julia Version 1.2.0
Commit c6da87ff4b (2019-08-20 00:03 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: AMD Ryzen 5 3600 6-Core Processor
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, znver1)
``````

Note that your error message is from `-` not `*`, so perhaps the next step is the problem, rather than `G = a*b`?

2 Likes

Dear @Tommaso_D_Amico

please consider:

1 Like