MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: concatenate matrices?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118180] Re: concatenate matrices?
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Fri, 15 Apr 2011 03:57:58 -0400 (EDT)

> I would guess that Transpose[{y1,y2}] is more readily understood by most  
> users.

It's not hard to understand, even if I had no reason for it. But I do.

Judicious use of //, /@, @, @@, @@@, /;, ->, :> and other shorthand  
constructs makes code easier to write and easier to read. They're all  
useful for the same reasons, and all have longer forms involving brackets.  
Even {a, b} is shorthand for List[a, b].

I use f @ arg when f has ONLY one argument, because it cuts down on both  
keystrokes and the forest of brackets, which can become difficult to  
visually match. Doubled part brackets, [], {}, ()... they proliferate, and  
breaking up the monotony helps the eye distinguish what's what. I might  
prefer f @ (a + b + c) to f[a + b + c], even though it doesn't reduce  
keystrokes, because it visually separates two ideas: addition on the one  
hand, and application of f on the other. If a list will have only ONE  
element, I will often write it List at a... particularly if a is already  
complicated, perhaps a list of its own.

Compare Sin@Exp@Sqrt@Norm@{x,f} with Sin[Exp[Sqrt[Norm[{x,y}]]]

Quick, now... did I get in exactly the right brackets on the second  
version????

Compare

{{{{1, 1}, {0, 0}, {1, 1}}, {{1, 1}, {1, 1}, {1, 0}}}}

with

List@{{{1, 1}, {0, 0}, {1, 1}}, {{1, 1}, {1, 1}, {1, 0}}}

Which makes it crystal clear, at a glance, what you're doing to an  
existing list?

// I reserve for "afterthought" operations (as I see them) such as

Plot[Table[x^k, {k, 3}]//Evaluate, {x,0,10},PlotStyle->{Red,Blue,Green}]

where Evaluate isn't changing what I want to plot... it prepares things so  
that Plot sees three functions and colors them separately, where without  
Evaluate, Plot would eventually see three, but too late to color them  
differently.

f @@ expr is clearer than Apply[f, expr] and easier to type.

f @@@ expr is simpler than Apply[f, expr, 1].

and so forth.

Bobby

On Thu, 14 Apr 2011 03:50:29 -0500, Robert Rosenbaum <robertr at math.uh.edu>  
wrote:

> DrMajorBob,
>
> A little off topic, but I was wondering why you suggested the prefix  
> notation
>> Transpose@{y1, y2}
> instead of
> Transpose[{y1,y2}]
>
> I've noticed other people doing the same on this mailing list, and  
> sometimes suggesting postfix as well.  I would guess that  
> Transpose[{y1,y2}] is more readily understood by most users.  Is there a  
> reason that you and others often suggest the arguably less common prefix  
> or postfix notations?
>
>
> Best,
> Robert
>
>
> On Apr 12, 2011, at 4:56 AM, DrMajorBob wrote:
>
>> Transpose@{y1, y2}
>>
>> Bobby
>>
>> On Mon, 11 Apr 2011 06:08:14 -0500, hadi motamedi <motamedi24 at gmail.com>
>> wrote:
>>
>>> Dear All
>>> I have two column matrices named y1 & y2 with dimensions as 448000*1 .
>>> Can you please let me know how to construct a new matrix say 'y' with
>>> dimensions 448000*2 such that each column of it equals y1(or y2)?
>>> Thank you
>>>
>>
>>
>> --
>> DrMajorBob at yahoo.com
>>
>
>
>
>
>
>
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: concatenate matrices?
  • Next by Date: Re: Plotting Locators with Color
  • Previous by thread: Re: concatenate matrices?
  • Next by thread: Re: concatenate matrices?