From e42ae01029caf63e28b7533d4f7fd03ac0244066 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 11 Mar 2021 16:44:53 -0700 Subject: Use more robust code for converting an array scalar to a shape () array --- numpy/_array_api/_array_object.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'numpy/_array_api/_array_object.py') 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 -- cgit v1.2.1