You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by gi...@git.apache.org on 2017/09/29 22:05:15 UTC
[GitHub] szha commented on a change in pull request #8104: correct boolean values for ndarray
szha commented on a change in pull request #8104: correct boolean values for ndarray
URL: https://github.com/apache/incubator-mxnet/pull/8104#discussion_r141977858
##########
File path: python/mxnet/ndarray/ndarray.py
##########
@@ -306,8 +306,14 @@ def __le__(self, other):
return lesser_equal(self, other)
def __bool__(self):
- raise ValueError("The truth value of an NDArray is ambiguous. " \
- "Please convert to number with asscalar() first.")
+ num_elements = reduce(operator.mul, self.shape, 1)
+ if num_elements == 0:
Review comment:
This is to be consistent with numpy array.
```python
In [1]: import numpy as np
In [2]: bool(np.array([]))
Out[2]: False
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services