@@ -412,14 +412,14 @@ def _unique_all_dispatcher(x, /):
412
412
@array_function_dispatch (_unique_all_dispatcher )
413
413
def unique_all (x ):
414
414
"""
415
- Find the unique elements of an array, and counts, inverse and indices.
415
+ Find the unique elements of an array, and counts, inverse, and indices.
416
416
417
- This function is an Array API compatible alternative to:
417
+ This function is an Array API compatible alternative to::
418
418
419
- >>> x = np.array([1, 1, 2])
420
- >>> np.unique(x, return_index =True, return_inverse=True,
421
- ... return_counts=True, equal_nan=False)
422
- (array([1, 2]), array([0, 2]), array([0, 0, 1]), array([2, 1]))
419
+ np.unique(x, return_index=True, return_inverse=True,
420
+ return_counts =True, equal_nan=False)
421
+
422
+ but returns a namedtuple for easier access to each output.
423
423
424
424
Parameters
425
425
----------
@@ -444,12 +444,16 @@ def unique_all(x):
444
444
Examples
445
445
--------
446
446
>>> import numpy as np
447
- >>> np.unique_all([1, 1, 2])
448
- UniqueAllResult(values=array([1, 2]),
449
- indices=array([0, 2]),
450
- inverse_indices=array([0, 0, 1]),
451
- counts=array([2, 1]))
452
-
447
+ >>> x = [1, 1, 2]
448
+ >>> uniq = np.unique_all(x)
449
+ >>> uniq.values
450
+ array([1, 2])
451
+ >>> uniq.indices
452
+ array([0, 2])
453
+ >>> uniq.inverse_indices
454
+ array([0, 0, 1])
455
+ >>> uniq.counts
456
+ array([2, 1])
453
457
"""
454
458
result = unique (
455
459
x ,
@@ -470,11 +474,11 @@ def unique_counts(x):
470
474
"""
471
475
Find the unique elements and counts of an input array `x`.
472
476
473
- This function is an Array API compatible alternative to:
477
+ This function is an Array API compatible alternative to::
474
478
475
- >>> x = np.array([1, 1, 2] )
476
- >>> np.unique(x, return_counts=True, equal_nan=False)
477
- (array([1, 2]), array([2, 1]))
479
+ np.unique(x, return_counts=True, equal_nan=False )
480
+
481
+ but returns a namedtuple for easier access to each output.
478
482
479
483
Parameters
480
484
----------
@@ -496,9 +500,12 @@ def unique_counts(x):
496
500
Examples
497
501
--------
498
502
>>> import numpy as np
499
- >>> np.unique_counts([1, 1, 2])
500
- UniqueCountsResult(values=array([1, 2]), counts=array([2, 1]))
501
-
503
+ >>> x = [1, 1, 2]
504
+ >>> uniq = np.unique_counts(x)
505
+ >>> uniq.values
506
+ array([1, 2])
507
+ >>> uniq.counts
508
+ array([2, 1])
502
509
"""
503
510
result = unique (
504
511
x ,
@@ -519,11 +526,11 @@ def unique_inverse(x):
519
526
"""
520
527
Find the unique elements of `x` and indices to reconstruct `x`.
521
528
522
- This function is Array API compatible alternative to:
529
+ This function is an Array API compatible alternative to::
530
+
531
+ np.unique(x, return_inverse=True, equal_nan=False)
523
532
524
- >>> x = np.array([1, 1, 2])
525
- >>> np.unique(x, return_inverse=True, equal_nan=False)
526
- (array([1, 2]), array([0, 0, 1]))
533
+ but returns a namedtuple for easier access to each output.
527
534
528
535
Parameters
529
536
----------
@@ -546,9 +553,12 @@ def unique_inverse(x):
546
553
Examples
547
554
--------
548
555
>>> import numpy as np
549
- >>> np.unique_inverse([1, 1, 2])
550
- UniqueInverseResult(values=array([1, 2]), inverse_indices=array([0, 0, 1]))
551
-
556
+ >>> x = [1, 1, 2]
557
+ >>> uniq = np.unique_inverse(x)
558
+ >>> uniq.values
559
+ array([1, 2])
560
+ >>> uniq.inverse_indices
561
+ array([0, 0, 1])
552
562
"""
553
563
result = unique (
554
564
x ,
@@ -569,11 +579,9 @@ def unique_values(x):
569
579
"""
570
580
Returns the unique elements of an input array `x`.
571
581
572
- This function is Array API compatible alternative to:
582
+ This function is an Array API compatible alternative to: :
573
583
574
- >>> x = np.array([1, 1, 2])
575
- >>> np.unique(x, equal_nan=False)
576
- array([1, 2])
584
+ np.unique(x, equal_nan=False)
577
585
578
586
Parameters
579
587
----------
0 commit comments