Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[Numpy][Operator] 'where' Implementation in MXNet #16829

Merged
merged 8 commits into from
Nov 18, 2019

Conversation

hgt312
Copy link
Contributor

@hgt312 hgt312 commented Nov 15, 2019

@hgt312 hgt312 requested a review from szha as a code owner November 15, 2019 11:30
@hgt312 hgt312 changed the title [Numpy][Operator] 'where' implementation in MXNet [Numpy][Operator] 'where' Implementation in MXNet Nov 15, 2019
@hgt312
Copy link
Contributor Author

hgt312 commented Nov 15, 2019

@mxnet-label-bot add [Numpy]

@xidulu
Copy link
Contributor

xidulu commented Nov 15, 2019

Two question:

  1. Numpy supports the following usage:
>>> import numpy as np
>>> a = np.random.uniform(size=(4,1))
>>> np.where(a > 0.5)
(array([0, 1, 2]), array([0, 0, 0]))

in short: x and y are optional ( either both or neither of x and y should be given)

  1. How did you handle the scalar case mentioned in the docstring?

https://github.com/apache/incubator-mxnet/pull/16829/files#diff-2867f3bd5e893c32c128044e32d821d6R7353-R7359

@hgt312
Copy link
Contributor Author

hgt312 commented Nov 15, 2019

@xidulu

  1. According to NumPy's doc, use np.nonzero, we have it.

When only condition is provided, this function is a shorthand for np.asarray(condition).nonzero(). Using nonzero directly should be preferred, as it behaves correctly for subclasses. The rest of this documentation covers only the case where all three arguments are provided.

  1. Does not support scalar now, just use np.array to wrap it.

Copy link
Contributor

@haojin2 haojin2 left a comment

Choose a reason for hiding this comment

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

LGTM other than the readability issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants