MathGroup Archive 2009

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

Search the Archive

Re: Can't apply Differences[] to a SparseArray[]?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg99351] Re: [mg99312] Can't apply Differences[] to a SparseArray[]?
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sun, 3 May 2009 05:23:47 -0400 (EDT)
  • References: <200905021001.GAA15469@smc.vnet.net>


On 2 May 2009, at 19:01, jmay wrote:

> Mathematica newbie here.
>
> I'd like to apply the Differences[] function to a sparse array.  Other
> list operations appear to work, but I'm seeing this:
>
>    s = SparseArray[{5, 6, 7} -> {10, 11, 12}]
>
>    Differences[s]
>
>        Differences::list: List expected at position 1 in Differences
> [SparseArray[Automatic,{7},0,{1,{{0,3},{{5},{6},{7}}},{10,11,12}}]].
>
> What is special about Differences?  I don't want to convert the sparse
> array to a regular list; my data set could have thousands or millions
> of missing elements.
>
> Thanks,
> -Jason
>

Probably an oversight in the implementation of Differences. As a work  
around try ListConvolve:

s = SparseArray[{5, 6, 7} -> {10, 11, 12}];

ListConvolve[{1, -1}, s]
{0, 0, 0, 10, 1, 1}

Andrzej Kozlowski



  • Prev by Date: Re: Introducing the Wolfram Mathematica Tutorial Collection
  • Next by Date: Re: Inverse function
  • Previous by thread: Can't apply Differences[] to a SparseArray[]?
  • Next by thread: Re: Can't apply Differences[] to a SparseArray[]?