MathGroup Archive 2010

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

Search the Archive

Re: SparseArray

  • To: mathgroup at
  • Subject: [mg109117] Re: SparseArray
  • From: Albert Retey <awnl at>
  • Date: Mon, 12 Apr 2010 23:05:05 -0400 (EDT)
  • References: <hputq9$lhm$>

Am 12.04.2010 12:48, schrieb Mala Jozsef:
> Hi, I would like to use SparseArray for large matrices and would like
> to use members of a list when giving values to the entries.Here is a
> simple example: l=={1}; SparseArray[{i_,i_}-> l[[i]],{1,1}]
> Part::pspec: Part specification i is neither an integer nor a list of
> integers. SparseArray[< 1 >,{1,1}]
> In fact it works if there are at most three list in the definition.
> Is there a solution without error messages? Thanks, Jozsef

>From the documenation:

With rules Subscript[pos, i]:>Subscript[val, i] the Subscript[val, i]
are evaluated separately for each set of indices that match
Subscript[pos, i].

So using RuleDelayed (:>) instead of just Rule (->) will prevent
evaluation of l[[i]] with a symbolic value for i which is the reason for
the error message:

SparseArray[{i_, i_} :> l[[i]], {1, 1}]



  • Prev by Date: Can you communicate about Mathematica?
  • Next by Date: Re: Change of function in an ODE
  • Previous by thread: SparseArray
  • Next by thread: ArrayPlot with inverted ColorFunction depending on MaxPlotPoints