Re: [sage-support] method to get the left-lower and right-upper triangular parts of a matrix

2015-05-20 Thread Vincent Delecroix

Hi,

On 20/05/15 08:54, Huayi Wei wrote:

Hi, Vincent,

Yes, my matrix is sparse.  I just move here from matlab, so I am a
newbie for sage and python.

The function you have offered can do the job. But I am worried about its
efficiency, because my sparse matrix
maybe very large which comes from Finite Element method.


The function I gave is not so bad, because if you have a sparse matrix 
accessing to a row (or even a slice of a row) gives you a sparse vector:


sage: m = matrix(100, sparse=True)
sage: v = m[5,5:]
sage: v.is_sparse()
True

Thouh I am not sure about the efficiency of

sage: m[5,5:] = v

when m is a sparse matrix and v a sparse vector. I quickly look at the 
code and it seems to run through all entries of v which is very stupid.



So about the efficient ways for  sparse matrix, can you give me some
suggestion?  Thanks very much.


If your matrix is sparse I would do

def triu(m):
t = matrix(m.base_ring(), m.nrows(), sparse=True)
for (i,j) in m.nonzero_positions():
if i <= j:
t[i,j] = m[i,j]
return t

Depending whether you want the diagonal or not you have to adjust the 
inequality for being strict or not.


Best,
Vincent

--
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] method to get the left-lower and right-uppertriangular parts of a matrix

2015-05-20 Thread 魏华祎
Hi, Vincent,

Thanks for your reply. I will try it following your suggestion.

Best

Huayi 
 
 
-- Original --
From:  "Vincent Delecroix"<20100.delecr...@gmail.com>;
Date:  Wed, May 20, 2015 03:55 PM
To:  "sage-support"; 

Subject:  Re: [sage-support] method to get the left-lower and 
right-uppertriangular parts of a matrix

 
Hi,

On 20/05/15 08:54, Huayi Wei wrote:
> Hi, Vincent,
>
> Yes, my matrix is sparse.  I just move here from matlab, so I am a
> newbie for sage and python.
>
> The function you have offered can do the job. But I am worried about its
> efficiency, because my sparse matrix
> maybe very large which comes from Finite Element method.

The function I gave is not so bad, because if you have a sparse matrix 
accessing to a row (or even a slice of a row) gives you a sparse vector:

sage: m = matrix(100, sparse=True)
sage: v = m[5,5:]
sage: v.is_sparse()
True

Thouh I am not sure about the efficiency of

sage: m[5,5:] = v

when m is a sparse matrix and v a sparse vector. I quickly look at the 
code and it seems to run through all entries of v which is very stupid.

> So about the efficient ways for  sparse matrix, can you give me some
> suggestion?  Thanks very much.

If your matrix is sparse I would do

def triu(m):
 t = matrix(m.base_ring(), m.nrows(), sparse=True)
 for (i,j) in m.nonzero_positions():
 if i <= j:
 t[i,j] = m[i,j]
 return t

Depending whether you want the diagonal or not you have to adjust the 
inequality for being strict or not.

Best,
Vincent

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Coefficient of element of polynomial ring over series ring

2015-05-20 Thread switzel
Suppose I have

K. = PowerSeriesRing(GF(2), 't')
R. = PolynomialRing(K, 'x, y')

and elt is an element of t. How do I obtain the coefficient of t in elt? Do 
I have to implement a coercion from R to 
PowerSeriesRing(PolynomialRing(GF(2), 'x, y'), 't')?

Also, assuming that the degree of t in elt is actually bounded, how can I 
turn elt into an element of PolynomialRing(GF(2), 'x, y, t')? I tried 
various versions of substitute() without success.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Did something happen with matrix_plot in 6.7

2015-05-20 Thread David Einstein
In 6.6 if I did
sage: matrix_plot(matrix([[1,2,3,4],[4,3,2,1]]))

I'd get a boring image (a bunch of squares)

In 6.7 I just get an axis.

This happens on my Mac OSX 10.10.3 and My linux machine (some recent 
Fedora).  Both sages are built from source.

There do not seem to be any open trac tickets for this, but I may be doing 
something wrong.  Am I?

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] About creating a bunch of matrices using "itertools"

2015-05-20 Thread Phoenix
I am trying to create the set of 3x3 matrices which have entries in the set 
[0,1,-1] 

The simple way to do that would be to create 9 nested loops and run over 
all the possibilities.  

One hopefully better way I could think of doing is possibly this,

from itertools import product
from itertools import izip

A = [(0,0),(0,1),(0,2),(1,0),(1,1),(1,2),(2,0),(2,1),(2,2)]

for a in  product([0,1,-1], repeat = 9):
B = izip (A,a)


I believe this "B" of mine encodes the matrix as a list of assignments as 
to which matrix entry has gotten which element of the list [0,1,-1] 

But I am not able to convert this B into something that actually is a 
matrix? 
(so that I can say take eigenvalues of it)  


Can someone help?

Also I am running things on the cloud.sage 








-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Re: Did something happen with matrix_plot in 6.7

2015-05-20 Thread John H Palmieri


On Wednesday, May 20, 2015 at 2:54:57 PM UTC-7, David Einstein wrote:
>
> In 6.6 if I did
> sage: matrix_plot(matrix([[1,2,3,4],[4,3,2,1]]))
>
> I'd get a boring image (a bunch of squares)
>
> In 6.7 I just get an axis.
>
> This happens on my Mac OSX 10.10.3 and My linux machine (some recent 
> Fedora).  Both sages are built from source.
>
> There do not seem to be any open trac tickets for this, but I may be doing 
> something wrong.  Am I?
>

It looks like a bug was introduced, my guess is in 
http://trac.sagemath.org/ticket/18327. I have now reported it at 
http://trac.sagemath.org/ticket/18463.

-- 
John
 

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] About creating a bunch of matrices using "itertools"

2015-05-20 Thread William Stein
On Wed, May 20, 2015 at 4:37 PM, Phoenix  wrote:
> I am trying to create the set of 3x3 matrices which have entries in the set
> [0,1,-1]
>
> The simple way to do that would be to create 9 nested loops and run over all
> the possibilities.

Use cartesian_product_iterator:

v = []
for x in cartesian_product_iterator([[0,1,-1]]*9):
v.append(matrix(3,x))

Complete example:

https://cloud.sagemath.com/projects/4a5f0542-5873-4eed-a85c-a18c706e8bcd/files/support/2015-05-20-matrices.sagews

>
> One hopefully better way I could think of doing is possibly this,
>
> from itertools import product
> from itertools import izip
>
> A = [(0,0),(0,1),(0,2),(1,0),(1,1),(1,2),(2,0),(2,1),(2,2)]
>
> for a in  product([0,1,-1], repeat = 9):
> B = izip (A,a)
>
>
> I believe this "B" of mine encodes the matrix as a list of assignments as to
> which matrix entry has gotten which element of the list [0,1,-1]
>
> But I am not able to convert this B into something that actually is a
> matrix?
> (so that I can say take eigenvalues of it)
>
>
> Can someone help?
>
> Also I am running things on the cloud.sage
>
>
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-support+unsubscr...@googlegroups.com.
> To post to this group, send email to sage-support@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.



-- 
William (http://wstein.org)

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.