Function with Matrix input [closed]

asked 2015-12-23 03:55:33 -0500

bruno171092 gravatar image

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?

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by bruno171092
close date 2015-12-23 09:17:19.763821



It 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()
vdelecroix gravatar imagevdelecroix ( 2015-12-23 04:57:39 -0500 )edit

Oops... that was quite some fail... Sorry :)

bruno171092 gravatar imagebruno171092 ( 2015-12-23 05:06:03 -0500 )edit

@bruno171092 The forum is exactly made for questions! If you are happy with my comment, could you close the question?

vdelecroix gravatar imagevdelecroix ( 2015-12-23 08:29:33 -0500 )edit