ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 21 May 2013 05:18:11 -0500Pulling the index of an entry of a matrixhttp://ask.sagemath.org/question/10144/pulling-the-index-of-an-entry-of-a-matrix/Let $M$ be some matrix, then I am looking for how to find out which entries of $M$ make the statement `M[i,j] == 25` true. Specifically, this is the code I'm using to generate the matrix, called `deg`:
deg = matrix(ZZ, 15)
A = lambda i: WeylCharacterRing("A{0}".format(i), style = "coroots")
for i in range(1,15):
fw = A(i).fundamental_weights()
for j in range(1,len(fw)):
deg[i,j] = A(i)(fw[j]).degree()
print deg
It works great, but now instead of printing deg and finding the entries manually, I would like to be able to store which entries `[i,j]` of `deg` are equal to 25 in some list, and then print that list, which would ideally look something like:
list(tfentry)
{ (2,3), (4,4) }
etc.
Any tips on where to look or help files to examine?
Thanks very much.
JoshIzzardTue, 21 May 2013 05:18:11 -0500http://ask.sagemath.org/question/10144/Assigning individual entries of a matrixhttp://ask.sagemath.org/question/10142/assigning-individual-entries-of-a-matrix/I have been using code as follows to compute fundamental weight representations of Lie groups inside $GL(25)$:
D = lambda i: WeylCharacterRing("D{0}".format(i), style = "coroots")
for i in range(2,12):
fw = D(i).fundamental_weights()
deg = D(i)(fw[1]).degree()
print deg
But now I am interested in going through and looking at all `D(i)(fw[j]).degree() for i in range(1,12), j in range(1,len(fw))`
Now this will be quite a set of numbers, so I am wondering how I can pick out the ones that give me `25` and then store the index of that matrix. Right now I have this:
import numpy
deg = numpy.zeros(12)
D = lambda i: WeylCharacterRing("D{0}".format(i), style = "coroots")
for i in range(2,12):
fw = D(i).fundamental_weights()
for j in range(1,len(fw)):
deg[i,j] = D(i)(fw[j]).degree()
print deg
But this doesn't work. Is my syntax off?JoshIzzardMon, 20 May 2013 10:00:35 -0500http://ask.sagemath.org/question/10142/sympy codegen with indiceshttp://ask.sagemath.org/question/8678/sympy-codegen-with-indices/I am doing a symbolic calculation in sage and I need a C-code of the output. I found an example in sympy documentation that does this.
from sympy import symbols
from sympy.utilities.codegen import codegen
from sympy.abc import x, y, z
[(c_name, c_code), (h_name, c_header)] = \
codegen(("f", x+y*z), "C", "test", header=False, empty=False)
print c_code,
However, this does not work when the variables I am passing to f have indices for example,
from sympy import symbols
from sympy.utilities.codegen import codegen
from sympy.abc import x[0], x[1], x[2]
[(c_name, c_code), (h_name, c_header)] = \
codegen(("f", x[0]+x[1]*x[2]), "C", "test", header=False, empty=False)
print c_code,
This results in an error. Is there a way to generate a C-code with indices in them?ShashankSat, 28 Jan 2012 10:42:55 -0600http://ask.sagemath.org/question/8678/Indexed family of functionshttp://ask.sagemath.org/question/8308/indexed-family-of-functions/I want to create a finite (but large-ish) sequence of symbolic functions f_0(x), f_1(x), etc. (up to, say, f_1000(x)). I can do this for any one function by typing something like:
f_4 = function('f_4', nargs=1)
Short of doing this 1000 times, how can I do this?
(For various reasons, I prefer having the subscript be part of the function's name rather than as a second variable.)jdcWed, 07 Sep 2011 16:10:58 -0500http://ask.sagemath.org/question/8308/