Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #11435 > unrolled thread

Re: Thread::tdlen: Objects of unequal length in

Started byBill Rowe <readnews@sbcglobal.net>
First post2012-08-21 09:01 +0000
Last post2012-08-21 09:01 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: Thread::tdlen: Objects of unequal length in Bill Rowe <readnews@sbcglobal.net> - 2012-08-21 09:01 +0000

#11435 — Re: Thread::tdlen: Objects of unequal length in

FromBill Rowe <readnews@sbcglobal.net>
Date2012-08-21 09:01 +0000
SubjectRe: Thread::tdlen: Objects of unequal length in
Message-ID<k0vipd$ouf$1@smc.vnet.net>
On 8/20/12 at 4:14 AM, aaron.sokolik@gmail.com (Aaron) wrote:

>I'm new to Mathematica and trying to run rebuild some programs from
>other systems in Mathematica.  I'm operating on large data lists and
>receiving the unequal length error.  However, if I simply paste the
>output without the extra curly bracket into an operation, everything
>works.  Obviously, copying and pasting wont work for functions...
>How can I get around this?

>Below are the functions I'm using to generate two lists from a
>single dataset:

>ln[13]:= MapThread[Mean, Sequence[{{testdata}}]]

It is not entirely clear as to what is being assigned to
testdata. So, I will assume you have two simple (1D) lists of
equal length. For example, starting with

a = RandomInteger[{0, 10}, 5];
b = RandomInteger[{11, 20}, 5];

Then I can set testData to

testData = {a, b};

With this I can do

In[4]:= MapThread[Mean[{##}] &, testData]

Out[4]= {13/2,13,11,27/2,29/2}

note the difference in syntax and note I get a list of 5
elements. That is I am averaging the first element of list a
with the first element of list b and so forth.

Notice

In[5]:= Dimensions[testData]

Out[5]= {2,5}

That is testData consists of two lists of equal length. Notice

In[6]:= Dimensions[Sequence[{{testData}}]]

Out[6]= {1,1,2,5}

additionally

In[7]:= Dimensions[{{testData}}]

Out[7]= {1,1,2,5}

That is Sequence isn't doing what you think and if you have
defined testData as I have above the result then {{testData}}
will not have the dimensional structure needed by MapThread. In
fact, MapThread is not needed at all since

In[8]:= Mean[testData]

Out[8]= {13/2,13,11,27/2,29/2}

produces exactly the same result. And if the your desire was to
have return the mean of list a along with the mean of list b
rather than averaging an element of list a with the
corresponding element of list b, you could do either

In[9]:= Mean /@ testData

Out[9]= {36/5,81/5}

or

In[9]:= Mean /@ testData

Out[9]= {36/5,81/5}

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web