Opened 13 years ago

Closed 12 years ago

#2396 closed defect (duplicate)

add support for matrix numpy-style indexing

Reported by: dfdeshom Owned by: dfdeshom
Priority: minor Milestone: sage-duplicate/invalid/wontfix
Component: linear algebra Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

Dan Christensen:

>  
>  Another nice feature of numpy is *assigning* using numpy-style indexing.
>  For example, to add a multiple of column j to column i, you can do
>  
>   A[:,i] += m*A[:,j]
>  
>  And you can zero out a region with
>  
>   A[2:4, 3:8] = 0    (broadcasting used here)

This is currently not implemented in sage.

Change History (3)

comment:1 Changed 13 years ago by dfdeshom

  • Owner changed from was to dfdeshom

comment:2 Changed 12 years ago by jason

See #4972, which may fix this.

comment:3 Changed 12 years ago by mvngu

  • Milestone changed from sage-4.1.2 to sage-duplicate/invalid/wontfix
  • Resolution set to duplicate
  • Status changed from new to closed

This has been fixed in Sage 4.1.2.alpha4:

[mvngu@sage sage-4.1.2.alpha4-sage.math]$ ./sage
----------------------------------------------------------------------
| Sage Version 4.1.2.alpha4, Release Date: 2009-09-27                |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
**********************************************************************
*                                                                    *
* Warning: this is a prerelease version, and it may be unstable.     *
*                                                                    *
**********************************************************************
sage: M = MatrixSpace(QQ, 9)
sage: A = M.random_element(); A

[   1   -2    2    2    0   -2  1/2    1  1/2]
[   0   -1    1    2    2    0    1   -1  1/2]
[ 1/2    2   -1    2  1/2    0   -1    2    1]
[   1   -1   -2    0 -1/2   -1   -1    0    2]
[   0   -1    0    0 -1/2   -2   -1    2    2]
[  -1    1   -1    0    2    0    1    0    1]
[   0    1    0    1 -1/2    1    1    2   -1]
[  -1 -1/2   -1    0   -1    0    0    2    0]
[   0 -1/2   -1    2    1    0    0    0    0]
sage: m = 3
sage: A[:,1] += m * A[:,4]
sage: A

[   1   -2    2    2    0   -2  1/2    1  1/2]
[   0    5    1    2    2    0    1   -1  1/2]
[ 1/2  7/2   -1    2  1/2    0   -1    2    1]
[   1 -5/2   -2    0 -1/2   -1   -1    0    2]
[   0 -5/2    0    0 -1/2   -2   -1    2    2]
[  -1    7   -1    0    2    0    1    0    1]
[   0 -1/2    0    1 -1/2    1    1    2   -1]
[  -1 -7/2   -1    0   -1    0    0    2    0]
[   0  5/2   -1    2    1    0    0    0    0]
sage: 
sage: A[2:4, 3:8] = 0
sage: A

[   1   -2    2    2    0   -2  1/2    1  1/2]
[   0    5    1    2    2    0    1   -1  1/2]
[ 1/2  7/2   -1    0    0    0    0    0    1]
[   1 -5/2   -2    0    0    0    0    0    2]
[   0 -5/2    0    0 -1/2   -2   -1    2    2]
[  -1    7   -1    0    2    0    1    0    1]
[   0 -1/2    0    1 -1/2    1    1    2   -1]
[  -1 -7/2   -1    0   -1    0    0    2    0]
[   0  5/2   -1    2    1    0    0    0    0]
sage: A[:,:] = 0
sage: A

[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0]

Closing this as a duplicate of #4972.

Note: See TracTickets for help on using tickets.