-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOC: Fix command in "Writing custom array containers" guide #18235
Conversation
The documentation is correct in its current form. The following paragraphs explain the difference between |
Allow me to insist:
I believe that the current version assumes that |
The output of Broken into finer steps: >>> arr = DiagonalArray(5, 1)
>>> type(arr)
__main__.DiagonalArray
>>> b = np.multiply(arr, 2)
>>> type(b)
numpy.ndarray |
@rossbar I understand all that but please read the document. It goes like this: >>> arr = DiagonalArray(5, 1)
>>> type(arr)
__main__.DiagonalArray
>>> np.multiply(arr, 2)
>>> type(arr)
numpy.ndarray which is wrong. Note how the output of |
Just to be clear, In your above example, you have >>> np.multiply(arr, 2)
>>> type(arr) Which would be incorrect, but is different than the original documentation. |
Sorry, no
No, it's not different. Are we looking at the same document? |
Here are the commands that are present in the master branch of the docs: In [1]: import numpy as np
In [2]: class DiagonalArray:
...: ... def __init__(self, N, value):
...: ... self._N = N
...: ... self._i = value
...: ... def __repr__(self):
...: ... return f"{self.__class__.__name__}(N={self._N}, value={self._i})"
...: ... def __array__(self):
...: ... return self._i * np.eye(self._N)
...:
In [3]: arr = DiagonalArray(5, 1)
In [4]: arr
Out[4]: DiagonalArray(N=5, value=1)
In [5]: np.asarray(arr)
Out[5]:
array([[1., 0., 0., 0., 0.],
[0., 1., 0., 0., 0.],
[0., 0., 1., 0., 0.],
[0., 0., 0., 1., 0.],
[0., 0., 0., 0., 1.]])
In [6]: np.multiply(arr, 2)
Out[6]:
array([[2., 0., 0., 0., 0.],
[0., 2., 0., 0., 0.],
[0., 0., 2., 0., 0.],
[0., 0., 0., 2., 0.],
[0., 0., 0., 0., 2.]])
In [7]: type(arr)
Out[7]: __main__.DiagonalArray. # <------ This is not ndarray unlike the docs claim!!!!!!!!! |
Wow - huge brainfart on my part - I just failed to interpret the diff correctly (I was assuming your change was what was already in the docs). So when I say "the original docs are correct", what I meant was "your original proposed changes are correct! Sorry for all the noise. |
No wonder I couldn't figure out why we were disagreeing even though I felt like we were saying the same thing :) - thanks for bearing with me @NicolasHug |
This is a minor doc fix: the
arr
object is of typeDiagonalArray
, notndarray
.I believe the point of this section is to illustrate that
type(np.multiply(arr, 2)) == np.ndarray