Skip to content

Added an 'elementary' function. - #4573

Closed
mttpgn wants to merge 10 commits into
numpy:masterfrom
mttpgn:master
Closed

Added an 'elementary' function.#4573
mttpgn wants to merge 10 commits into
numpy:masterfrom
mttpgn:master

Conversation

@mttpgn

@mttpgn mttpgn commented Mar 31, 2014

Copy link
Copy Markdown

The new function creates an identity array that's had a single row operation performed on it. Quite useful when doing matrix multiplication. https://en.wikipedia.org/wiki/Elementary_matrix

Comment thread numpy/lib/twodim_base.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"are square by definition", perhaps?

@perimosocordiae

Copy link
Copy Markdown
Contributor

Im not sure whether this function should be added, but it will definitely need test cases as well if it is.

Comment thread numpy/lib/twodim_base.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8 wants spaces around operators. Also checking for None should be done with is.

@mttpgn

mttpgn commented Apr 9, 2014

Copy link
Copy Markdown
Author

Tests are still forthcoming.

@njsmith

njsmith commented Apr 9, 2014

Copy link
Copy Markdown
Member

I haven't looked at this in detail, but yes, please don't use np.matrix in
new code or docs.

For now the best way to write matrix multiplication is just as a call to
np.dot.
On 9 Apr 2014 22:24, "Matt Pagan" notifications@github.com wrote:

Tests are still forthcoming.


Reply to this email directly or view it on GitHubhttps://github.com//pull/4573#issuecomment-40018304
.

@mttpgn

mttpgn commented Jul 26, 2014

Copy link
Copy Markdown
Author

So, I've added test coverage, switched to using np.dot instead of np.matrix, dropped the string formatting, and reworded the documentation. What do numpy devs think of this patch? Any other thoughts?

@juliantaylor

Copy link
Copy Markdown
Contributor

hm elementary matrices may be useful for mathematical notation, but why would you want to use them computations?
E.g. if you want to swap two rows of a matrix, it is far more efficient to just swap them instead of creating an elementary matrix and the doing a very expensive matrix multiplication.

@larsmans

Copy link
Copy Markdown
Contributor

You might want to compose several linear transformations by multiplying their corresponding matrices together.

@juliantaylor

Copy link
Copy Markdown
Contributor

hm it would still be very inefficient. But its probably useful for code clarity on operations where performance does not matter and could become more useful for other cases when numpy gains a smart matrix-dot chaining function.

@njsmith

njsmith commented Jul 26, 2014

Copy link
Copy Markdown
Member

Other cases I can imagine it might be useful:

  • have an API that takes an arbitrary matrix, want to pass in an elementary
    matrix
  • teaching
    On 26 Jul 2014 13:51, "Julian Taylor" notifications@github.com wrote:

hm it would still be very inefficient. But its probably useful for code
clarity on operations where performance does not matter and could become
more useful for other cases when numpy gains a smart matrix-dot chaining
function.


Reply to this email directly or view it on GitHub
#4573 (comment).

@juliantaylor

Copy link
Copy Markdown
Contributor
In [11]: elementary(3,0,1, multiplier=3)
Out[11]: 
array([[ 1.,  0.,  0.],
       [ 3.,  1.,  0.],
       [ 0.,  0.,  1.]])

is the last 1 on the diagonal correct here? it isn't a multiplier anymore in this case.

@charris

charris commented Aug 8, 2014

Copy link
Copy Markdown
Member

Needs rebase.

Comment thread numpy/lib/twodim_base.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to document the dtype arg?

@argriffing

Copy link
Copy Markdown
Contributor

I was looking for a numpy elementary function that returns row j of the identity matrix without actually constructing the identity matrix, and I found this PR which does a different thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.