ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 25 Jul 2022 15:15:11 +0200Pulling the index of an entry of a matrixhttps://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 12:18:11 +0200https://ask.sagemath.org/question/10144/Matrix with negative indiceshttps://ask.sagemath.org/question/63397/matrix-with-negative-indices/Is there a way or hack to operate with matrices with negative indices? For example a 3x3 matrix with row indices {-1,0,1} and column indices {-1, 0, 1}. So one can do m[-1,-1] for first row and column entry, while still retain matrix operations (ring ops, determinant, etc.). I'm dealing with random walks where the symetry needs that.jesuslopMon, 25 Jul 2022 15:15:11 +0200https://ask.sagemath.org/question/63397/R_{ab} = T_{ba} and so onhttps://ask.sagemath.org/question/62753/r_ab-t_ba-and-so-on/ How can I permute indices in tensor fields on manifolds? I would like to define the following (0,4) tensor
$R_{abcd} = g_{a[c}g_{d]b}$
but I can't find an "easy" way (apart from assigning all the components bruteforce with some for loop, I guess). I presume there should be an "ovious" way of doing that but I cannot find it. Thanks.solidsnakeSun, 05 Jun 2022 12:54:58 +0200https://ask.sagemath.org/question/62753/How to recover indices ?https://ask.sagemath.org/question/60271/how-to-recover-indices/ Suppose I have indexed variables as
z=[var(f'p_{k}{l}') for k in range(2) for l in range(4)]
I can easily print `z[6]`. But what I want to use is it's two indices. How can I recover them ?
CyrillePWed, 15 Dec 2021 11:29:05 +0100https://ask.sagemath.org/question/60271/Assigning individual entries of a matrixhttps://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 17:00:35 +0200https://ask.sagemath.org/question/10142/sympy codegen with indiceshttps://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 17:42:55 +0100https://ask.sagemath.org/question/8678/Indexed family of functionshttps://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 23:10:58 +0200https://ask.sagemath.org/question/8308/