Re: sparsearray bug?

• To: mathgroup at smc.vnet.net
• Subject: [mg101634] Re: sparsearray bug?
• From: wpb <wicher.bergsma at googlemail.com>
• Date: Sun, 12 Jul 2009 05:48:57 -0400 (EDT)
• References: <h375sk\$esp\$1@smc.vnet.net>

```Dividing a SparseArray by another can be needed eg in the following
situation: A is a sparse matrix, b and c nonsparse vectors and we want
to compute A.(b/c). Seems to be best to numerically to put everything
in SparseArray form I think...

> On Jul 10, 11:41 am, Bill Rowe <readn... at sbcglobal.net> wrote:
> On 7/8/09 at 7:11 AM, w.p.berg... at lse.ac.uk (wpb) wrote:
>
> >In[494]:= SparseArray[{1}]/SparseArray[{1}]
> >During evaluation of In[494]:= Power::infy: Infinite expression 1/0
> >encountered. >> During evaluation of In[494]:= \[Infinity]::indet:
> >Indeterminate expression 0 ComplexInfinity encountered. >>
> >Out[494]= SparseArray[<1>,{1},Indeterminate]
>
> What were you expecting and why would you ever divide one sparse
> array by another?
>
> Consider for normal arrays the following:
>
> In[3]:= x = RandomReal[1, {2, 2}]
>
> Out[3]= {{0.980046, 0.324877}, {0.587326, 0.387608}}
>
> In[4]:= y = RandomReal[1, {2, 2}]
>
> Out[4]= {{0.554456, 0.960964}, {0.162428, 0.976886}}
>
> In[5]:= x/y
>
> Out[5]= {{1.76758, 0.338074}, {3.61592, 0.396779}}
>
> Since the divide operation does an element by element divide you
> should expect the same behavior when dividing a sparse array by
> another sparse array. But by definition a sparse array has a
> great many elements with value 0. So, an element by element
> divide will inevitably mean dividing by 0.
>
> above since SparseArray[{1}] is the one element array {1}.
> Possibly the code that does the element by element divide does
> not look to see that SparseArray[{1}] isn't really a sparse
> array in the since there are no zero elements.
>
> But even if this is a bug (meaning the results are different
> than intended) it still leaves the question of why would you be
> doing this kind of division?

```

• Prev by Date: Re: Re: 2dFFT & image processing
• Next by Date: Re: Calculate n in binomial distribution
• Previous by thread: Re: sparsearray bug?
• Next by thread: Re: sparsearray bug?