File tree Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -465,7 +465,40 @@ def flatten(self, order='C'):
465
465
466
466
# 'getfield',
467
467
# 'imag',
468
- # 'item',
468
+
469
+ def item (self , id = None ):
470
+ """
471
+ Copy an element of an array to a standard Python scalar and return it.
472
+
473
+ For full documentation refer to :obj:`numpy.ndarray.item`.
474
+
475
+ Examples
476
+ --------
477
+ >>> np.random.seed(123)
478
+ >>> x = np.random.randint(9, size=(3, 3))
479
+ >>> x
480
+ array([[2, 2, 6],
481
+ [1, 3, 6],
482
+ [1, 0, 1]])
483
+ >>> x.item(3)
484
+ 1
485
+ >>> x.item(7)
486
+ 0
487
+ >>> x.item((0, 1))
488
+ 2
489
+ >>> x.item((2, 2))
490
+ 1
491
+
492
+ """
493
+
494
+ if id is None :
495
+ if self .size != 1 :
496
+ raise ValueError ("DPNP dparray::item(): can only convert an array of size 1 to a Python scalar" )
497
+ else :
498
+ id = 0
499
+
500
+ return self .flat [id ]
501
+
469
502
# 'itemset',
470
503
471
504
@property
Original file line number Diff line number Diff line change @@ -22,9 +22,6 @@ tests/test_random.py::TestDistributionsMultinomial::test_seed
22
22
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.astype(dpnp.asarray(x), dpnp.int8)]
23
23
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.astype(dpnp.asarray(x), object)]
24
24
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.vstack([x, x]).T]
25
- tests/third_party/cupy/core_tests/test_ndarray_conversion.py::TestNdarrayItem_param_0_{shape=()}::test_item
26
- tests/third_party/cupy/core_tests/test_ndarray_conversion.py::TestNdarrayItem_param_1_{shape=(1,)}::test_item
27
- tests/third_party/cupy/core_tests/test_ndarray_conversion.py::TestNdarrayItem_param_2_{shape=(1, 1, 1)}::test_item
28
25
tests/third_party/cupy/core_tests/test_ndarray_conversion.py::TestNdarrayItemRaise_param_0_{shape=(0,)}::test_item
29
26
tests/third_party/cupy/core_tests/test_ndarray_conversion.py::TestNdarrayItemRaise_param_1_{shape=(2, 3)}::test_item
30
27
tests/third_party/cupy/core_tests/test_ndarray_conversion.py::TestNdarrayItemRaise_param_2_{shape=(1, 0, 1)}::test_item
You can’t perform that action at this time.
0 commit comments