Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: Re: problem with Pick

  • To: mathgroup at smc.vnet.net
  • Subject: [mg78250] Re: [mg78222] Re: [mg78194] problem with Pick
  • From: "Chris Chiasson" <chris at chiasson.name>
  • Date: Wed, 27 Jun 2007 05:18:57 -0400 (EDT)
  • References: <acbec1a40706230431p4f1db9a9i4320680dda027396@mail.gmail.com>

On 6/26/07, Andrzej Kozlowski <akoz at mimuw.edu.pl> plays Devil's advocate (;-)):
>   It is not actually the case that in this respect we have  "one way
> for SparseArray and another way for lists" because "the way for
> lists" is in fact the way for most other selectors except
> SparseArrays. For example, using an arbitrary head f, we have:
>
> Pick[{a, b}, f[2, 3], Except[2]]
> {a, b}
>
> which behaves the same way as List. The fact that SparseArray behaves
> in a special way becoems clear if you examine its FullForm:

You have sufficiently demonstrated that, when used as the selector in
Pick, SparseArray is not matched at level zero like List and general
expressions of other heads. However, you haven't provided a reason why
the situation should be that way. Also, not to be pedantic, but

>   It is not actually the case that in this respect we have  "one way
> for SparseArray and another way for lists"

is false.

>   FullForm[SparseArray[{1, 2}]]
>   FullForm[SparseArray[Automatic, {2}, 0, {1, {{0, 2}, {{1}, {2}}},
> {1, 2}}]]
>
> Normally, it is the FullForm of the expression that is used in Pick
> (or for pattern matching) but of course it would be extremly
> inconvenient if this were the case with SparseArrays.
>
> Actually, not only SparseArray but also other atomic expressions are
> also treated in "special ways", for example:
>
> Pick[{a, b}, Complex[2, 3], 2]
> Sequence[]
>
> Pick[{a, b}, complex[2, 3], 2]
> {a}
>
> Note that List[a,b] is not an atom and there is no reason to treat it
> in any way different from the way one treats an expression with an
> arbitrary head f. On the other hand,
>
> AtomQ[SparseArray@{1, 2}]
> True
>
> and Atoms in Mathematica are generally treated in special ways as far
> as pattern matching or Part extraction are concerned.

I agree with these statements, but they are somewhat peripheral to
determining the intended behavior of Pick and making the documentation
consistent. It seems you are not actually taking a position, but are
illuminating certain concepts.


-- 
http://chris.chiasson.name/


  • Prev by Date: Re: Summations
  • Next by Date: Re: search for an operator in an expression
  • Previous by thread: Re: Re: problem with Pick
  • Next by thread: Re: Re: problem with Pick