Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Weird behavior of SparseArray

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58387] Weird behavior of SparseArray
  • From: Adel Elsabbagh <aelsabbagh at gmail.com>
  • Date: Thu, 30 Jun 2005 04:37:22 -0400 (EDT)
  • Reply-to: Adel Elsabbagh <aelsabbagh at gmail.com>
  • Sender: owner-wri-mathgroup at wolfram.com

Dear all

I don't understand what is going on with SparseArray

If I write this:

cp1 = SparseArray[{i_, j_} -> 0, {4, 2}];
cp1[[Range[4], 1]] = cp1[[Range[4], 1]] + {1, 1, 1, 1};
cp1 // MatrixForm

I get cp1 with all entries equal to zero

However, if use Table instead of SparseArray I get the right answer.

More surprisingly, if I write this: 

cp1 = SparseArray[{i_, j_} -> 0, {4, 2}];
cp1[[Range[4], 1]] = cp1[[Range[4], 1]] + {1, 1, 1, 1};
cp1 // MatrixForm
cp1[[Range[4], 1]] = cp1[[Range[4], 1]] + {1, 1, 1, 1};
cp1 // MatrixForm

I get ones in the first column!!

Any explanation?

-- 
Adel


  • Prev by Date: Integrate and Boole problems
  • Next by Date: Re: (presumably) easy AspectRatio question
  • Previous by thread: Integrate and Boole problems
  • Next by thread: Re: Weird behavior of SparseArray