Function with Matrix input [closed]

asked 2015-12-23 10:55:33 +0200

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 16: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 11:57:39 +0200 )edit

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

bruno171092 gravatar imagebruno171092 ( 2015-12-23 12:06:03 +0200 )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 15:29:33 +0200 )edit