[Date Index]
[Thread Index]
[Author Index]
Re: Thread::tdlen: Objects of unequal length in
*To*: mathgroup at smc.vnet.net
*Subject*: [mg127773] Re: Thread::tdlen: Objects of unequal length in
*From*: Bill Rowe <readnews at sbcglobal.net>
*Date*: Tue, 21 Aug 2012 04:59:32 -0400 (EDT)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
*Delivered-to*: l-mathgroup@wolfram.com
*Delivered-to*: mathgroup-newout@smc.vnet.net
*Delivered-to*: mathgroup-newsend@smc.vnet.net
On 8/20/12 at 4:14 AM, aaron.sokolik at 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}
Prev by Date:
**Re: Thread::tdlen: Objects of unequal length in**
Next by Date:
**Re: Drawing a Line From One Plot to Another**
Previous by thread:
**Re: Thread::tdlen: Objects of unequal length in**
Next by thread:
**How to make fitting code using NDSolve?**
| |