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.Wed, 23 Dec 2015 15:29:33 +0100Function with Matrix inputhttps://ask.sagemath.org/question/31787/function-with-matrix-input/ Hello Guys i have the following problem.
I want to write a function whose input is a Matrix. A small example:
def Dimension(Matrix):
n = Matrix.nrows()
return n
A = ([1,0,0],[0,1,0],[0,0,1])
print Dimension(A)
but then i get :
AttributeError: 'tuple' object has no attribute 'nrows'
How can I write i function that has an Matrix as input?Wed, 23 Dec 2015 10:55:33 +0100https://ask.sagemath.org/question/31787/function-with-matrix-input/Comment by vdelecroix for <p>Hello Guys i have the following problem.</p>
<p>I want to write a function whose input is a Matrix. A small example:</p>
<pre><code> def Dimension(Matrix):
n = Matrix.nrows()
return n
A = ([1,0,0],[0,1,0],[0,0,1])
print Dimension(A)
</code></pre>
<p>but then i get :</p>
<pre><code>AttributeError: 'tuple' object has no attribute 'nrows'
</code></pre>
<p>How can I write i function that has an Matrix as input?</p>
https://ask.sagemath.org/question/31787/function-with-matrix-input/?comment=31790#post-id-31790It would be better if you call the function with a matrix as input and not a tuple
sage: A = ([1,0,0],[0,1,0],[0,0,1])
sage: type(A)
<type 'tuple'>
sage: A.nrows()
Traceback (most recent call last):
...
AttributeError: 'tuple' object has no attribute 'nrows'
sage: m = matrix(A)
sage: m.nrows()
3Wed, 23 Dec 2015 11:57:39 +0100https://ask.sagemath.org/question/31787/function-with-matrix-input/?comment=31790#post-id-31790Comment by bruno171092 for <p>Hello Guys i have the following problem.</p>
<p>I want to write a function whose input is a Matrix. A small example:</p>
<pre><code> def Dimension(Matrix):
n = Matrix.nrows()
return n
A = ([1,0,0],[0,1,0],[0,0,1])
print Dimension(A)
</code></pre>
<p>but then i get :</p>
<pre><code>AttributeError: 'tuple' object has no attribute 'nrows'
</code></pre>
<p>How can I write i function that has an Matrix as input?</p>
https://ask.sagemath.org/question/31787/function-with-matrix-input/?comment=31791#post-id-31791Oops... that was quite some fail... Sorry :)Wed, 23 Dec 2015 12:06:03 +0100https://ask.sagemath.org/question/31787/function-with-matrix-input/?comment=31791#post-id-31791Comment by vdelecroix for <p>Hello Guys i have the following problem.</p>
<p>I want to write a function whose input is a Matrix. A small example:</p>
<pre><code> def Dimension(Matrix):
n = Matrix.nrows()
return n
A = ([1,0,0],[0,1,0],[0,0,1])
print Dimension(A)
</code></pre>
<p>but then i get :</p>
<pre><code>AttributeError: 'tuple' object has no attribute 'nrows'
</code></pre>
<p>How can I write i function that has an Matrix as input?</p>
https://ask.sagemath.org/question/31787/function-with-matrix-input/?comment=31796#post-id-31796@bruno171092 The forum is exactly made for questions! If you are happy with my comment, could you close the question?Wed, 23 Dec 2015 15:29:33 +0100https://ask.sagemath.org/question/31787/function-with-matrix-input/?comment=31796#post-id-31796