Re: SparseArray
- To: mathgroup at smc.vnet.net
- Subject: [mg109117] Re: SparseArray
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Mon, 12 Apr 2010 23:05:05 -0400 (EDT)
- References: <hputq9$lhm$1@smc.vnet.net>
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}] hth, albert