Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#13571 closed defect (invalid)

Matrix Entries Can Be Callable Objects not tested

Reported by: startakovsky Owned by: tbd
Priority: minor Milestone: sage-duplicate/invalid/wontfix
Component: PLEASE CHANGE Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by startakovsky)

In the documentation, http://www.sagemath.org/doc/reference/sage/matrix/constructor.html,

it states that matrices can pass in callable objects, though there is no example or test of this here. Is there documentation at least showing a test of this functionality? If not, it probably should be added, if not for the end user, at least to ensure it doesn't break.

In the meanwhile, any tip on getting a matrix like: ` ['apple', 'frog']

[[3,2] , 3 ]`

Change History (5)

comment:1 Changed 10 years ago by startakovsky

  • Description modified (diff)

comment:2 Changed 10 years ago by startakovsky

  • Description modified (diff)

comment:3 Changed 10 years ago by startakovsky

  • Priority changed from major to minor
  • Type changed from PLEASE CHANGE to defect

comment:4 Changed 10 years ago by mhansen

  • Resolution set to invalid
  • Status changed from new to closed

It gives examples of passing in a callable object:

sage: m = matrix(QQ, 3, 3, lambda i, j: i+j); m
[0 1 2]
[1 2 3]
[2 3 4]
sage: m = matrix(3, lambda i,j: i-j); m
[ 0 -1 -2]
[ 1  0 -1]
[ 2  1  0]
sage: matrix(QQ,2,3,lambda x, y: x+y)
[0 1 2]
[1 2 3]
sage: matrix(QQ,3,2,lambda x, y: x+y)
[0 1]
[1 2]
[2 3]

It is impossible to get a matrix like

['apple', 'frog']
[[3,2]  , 3     ]

since a matrix requires that the entries be elements of a ring (so things like multiplication and addition are defined). You could either use a list of lists or a numpy array like

sage: import numpy as np
sage: a = np.array([['apple', 'frog'],[[3,2], 3]], dtype=object); a
array([[apple, frog],
       [[3, 2], 3]], dtype=object)
sage: a[1,0]
[3, 2]
sage: a.transpose()
array([[apple, [3, 2]],
       [frog, 3]], dtype=object)
Last edited 10 years ago by mhansen (previous) (diff)

comment:5 Changed 10 years ago by mhansen

  • Milestone changed from sage-5.5 to sage-duplicate/invalid/wontfix
Note: See TracTickets for help on using tickets.