Thank you for your help, Jason.
Can I get some help on the following matrix too?
a_{i,j} = 1 for 1 \leq i \leq 5 and j \in \{1,2,3, 7, ..., 20};
a_{i,j} =3 for i \in \{6, 7, 13, ..., 19\};
a_{ij}=-1 otherwise
>P.S. If you have any suggestions for improving the linear algebra or
>making it easier to use, we'd love to hear them!
I would be happy to do so (I just started to use sage though).
In-Jae
________________________________________
From: [email protected] [[email protected]] On Behalf
Of Jason Grout [[email protected]]
Sent: Thursday, June 04, 2009 1:43 PM
To: [email protected]
Subject: [sage-support] Re: matrix with many repeated entries
Kim, In-Jae wrote:
> Hello,
>
> I would like to create a matrix with many repeated entries, for example, a
> matrix with all entries equal to 1.
> How can I do this efficiently when the size of the matrix is large?
>
Hi In-Jae,
In Python (i.e., Sage), you can duplicate a list by multiplying it by a
number:
sage: [1]*20
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
So you would just use that to create a list long enough for your matrix:
sage: matrix(4,5,[1]*20)
[1 1 1 1 1]
[1 1 1 1 1]
[1 1 1 1 1]
[1 1 1 1 1]
Thanks,
Jason
P.S. If you have any suggestions for improving the linear algebra or
making it easier to use, we'd love to hear them!
--
Jason Grout
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---