summaryrefslogtreecommitdiff
path: root/numpy/_array_api/_array_object.py
diff options
context:
space:
mode:
authorAaron Meurer <asmeurer@gmail.com>2021-03-11 16:44:53 -0700
committerAaron Meurer <asmeurer@gmail.com>2021-03-11 16:44:53 -0700
commite42ae01029caf63e28b7533d4f7fd03ac0244066 (patch)
tree77639a64f4254cc6c405a66aebf130472a6ebe49 /numpy/_array_api/_array_object.py
parentda5dc954ea5e5a1c4fc43240f4ddfec051d71845 (diff)
downloadnumpy-e42ae01029caf63e28b7533d4f7fd03ac0244066.tar.gz
Use more robust code for converting an array scalar to a shape () array
Diffstat (limited to 'numpy/_array_api/_array_object.py')
-rw-r--r--numpy/_array_api/_array_object.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/numpy/_array_api/_array_object.py b/numpy/_array_api/_array_object.py
index e9ea6ef45..371361de9 100644
--- a/numpy/_array_api/_array_object.py
+++ b/numpy/_array_api/_array_object.py
@@ -54,8 +54,10 @@ class ndarray:
obj = super().__new__(cls)
# Note: The spec does not have array scalars, only shape () arrays.
if isinstance(x, np.generic):
- # x[...] converts an array scalar to a shape () array.
- x = x[...]
+ # Convert the array scalar to a shape () array
+ xa = np.empty((), x.dtype)
+ xa[()] = x
+ x = xa
obj._array = x
return obj