Thank you very much for the response.
But the behavior of the same in scipy is different i.e., it omits the
elements. Is this not the expected behavior ?? The same result is as
follows using scipy and numpy :
>>> import numpy as np
>>> import scipy.sparse as sp
>>> m = np.arange(3, -4, -1)
>>> t = sp.spdiags(m,1,len(m),len(m))
>>> t
<7x7 sparse matrix of type '<type 'numpy.int64'>'
with 6 stored elements (1 diagonals) in DIAgonal format>
>>> t.toarray()
array([[ 0, 2, 0, 0, 0, 0, 0],
[ 0, 0, 1, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, -1, 0, 0],
[ 0, 0, 0, 0, 0, -2, 0],
[ 0, 0, 0, 0, 0, 0, -3],
[ 0, 0, 0, 0, 0, 0, 0]])
On Tuesday, March 10, 2015 at 11:58:39 PM UTC+5:30, Steven G. Johnson wrote:
>
>
>> But when I give in
>> julia> spdiagm(x, 1, length(x), length(x))
>> ERROR: BoundsError
>> in sparse at sparse/csparse.jl:50
>> in spdiagm at sparse/sparsematrix.jl:2133
>> in spdiagm at sparse/sparsematrix.jl:2141
>>
>> I get the above error. Any leads on this would be great. Thanks.
>>
>
> You need to use length(x)+1. If you have an MxM matrix, then the k-th
> diagonal has M-k entries. You are supplying M entries for the 1st
> diagonal, which is too many.
>