@@ -373,7 +373,15 @@ def astype(self, dtype, order='K', casting='unsafe', subok=True, copy=True):
373
373
374
374
# 'base',
375
375
# 'byteswap',
376
- # 'choose',
376
+
377
+ def choose (input , choices , out = None , mode = 'raise' ):
378
+ """
379
+ Construct an array from an index array and a set of arrays to choose from.
380
+
381
+ """
382
+
383
+ return dpnp .choose (input , choices , out , mode )
384
+
377
385
# 'clip',
378
386
# 'compress',
379
387
@@ -408,7 +416,19 @@ def conjugate(self):
408
416
# 'cumprod',
409
417
# 'cumsum',
410
418
# 'data',
411
- # 'diagonal',
419
+
420
+ def diagonal (input , offset = 0 , axis1 = 0 , axis2 = 1 ):
421
+ """
422
+ Return specified diagonals.
423
+
424
+ See Also
425
+ --------
426
+ :obj:`dpnp.diagonal`
427
+
428
+ """
429
+
430
+ return dpnp .diagonal (input , offset , axis1 , axis2 )
431
+
412
432
# 'dot',
413
433
414
434
@property
@@ -420,7 +440,32 @@ def dtype(self):
420
440
421
441
# 'dump',
422
442
# 'dumps',
423
- # 'fill',
443
+
444
+ def fill (self , value ):
445
+ """
446
+ Fill the array with a scalar value.
447
+
448
+ Parameters
449
+ ----------
450
+ value : scalar
451
+ All elements of `a` will be assigned this value.
452
+
453
+ Examples
454
+ --------
455
+ >>> a = np.array([1, 2])
456
+ >>> a.fill(0)
457
+ >>> a
458
+ array([0, 0])
459
+ >>> a = np.empty(2)
460
+ >>> a.fill(1)
461
+ >>> a
462
+ array([1., 1.])
463
+
464
+ """
465
+
466
+ for i in range (self .size ):
467
+ self .flat [i ] = value
468
+
424
469
# 'flags',
425
470
426
471
@property
@@ -465,7 +510,40 @@ def flatten(self, order='C'):
465
510
466
511
# 'getfield',
467
512
# 'imag',
468
- # 'item',
513
+
514
+ def item (self , id = None ):
515
+ """
516
+ Copy an element of an array to a standard Python scalar and return it.
517
+
518
+ For full documentation refer to :obj:`numpy.ndarray.item`.
519
+
520
+ Examples
521
+ --------
522
+ >>> np.random.seed(123)
523
+ >>> x = np.random.randint(9, size=(3, 3))
524
+ >>> x
525
+ array([[2, 2, 6],
526
+ [1, 3, 6],
527
+ [1, 0, 1]])
528
+ >>> x.item(3)
529
+ 1
530
+ >>> x.item(7)
531
+ 0
532
+ >>> x.item((0, 1))
533
+ 2
534
+ >>> x.item((2, 2))
535
+ 1
536
+
537
+ """
538
+
539
+ if id is None :
540
+ if self .size != 1 :
541
+ raise ValueError ("DPNP dparray::item(): can only convert an array of size 1 to a Python scalar" )
542
+ else :
543
+ id = 0
544
+
545
+ return self .flat [id ]
546
+
469
547
# 'itemset',
470
548
471
549
@property
@@ -514,9 +592,50 @@ def ndim(self):
514
592
# 'ravel',
515
593
# 'real',
516
594
# 'repeat',
517
- # 'reshape',
595
+
596
+ def reshape (self , d0 , * dn , order = b'C' ):
597
+ """
598
+ Returns an array containing the same data with a new shape.
599
+
600
+ Refer to `dpnp.reshape` for full documentation.
601
+
602
+ .. seealso::
603
+ :meth:`numpy.ndarray.reshape`
604
+
605
+ Notes
606
+ -----
607
+ Unlike the free function `dpnp.reshape`, this method on `ndarray` allows
608
+ the elements of the shape parameter to be passed in as separate arguments.
609
+ For example, ``a.reshape(10, 11)`` is equivalent to
610
+ ``a.reshape((10, 11))``.
611
+
612
+ """
613
+
614
+ if dn :
615
+ if not isinstance (d0 , int ):
616
+ msg_tmpl = "'{}' object cannot be interpreted as an integer"
617
+ raise TypeError (msg_tmpl .format (type (d0 ).__name__ ))
618
+ shape = [d0 , * dn ]
619
+ else :
620
+ shape = d0
621
+
622
+ shape_tup = dpnp .dpnp_utils ._object_to_tuple (shape )
623
+
624
+ return dpnp .reshape (self , shape_tup )
625
+
518
626
# 'resize',
519
- # 'round',
627
+
628
+ def round (self , decimals = 0 , out = None ):
629
+ """
630
+ Return array with each element rounded to the given number of decimals.
631
+
632
+ .. seealso::
633
+ :obj:`dpnp.around` for full documentation.
634
+
635
+ """
636
+
637
+ return dpnp .around (self , decimals , out )
638
+
520
639
# 'searchsorted',
521
640
# 'setfield',
522
641
# 'setflags',
@@ -561,7 +680,17 @@ def size(self):
561
680
return self ._array_obj .size
562
681
563
682
# 'sort',
564
- # 'squeeze',
683
+
684
+ def squeeze (self , axis = None ):
685
+ """
686
+ Remove single-dimensional entries from the shape of an array.
687
+
688
+ .. seealso::
689
+ :obj:`dpnp.squeeze` for full documentation
690
+
691
+ """
692
+
693
+ return dpnp .squeeze (self , axis )
565
694
566
695
def std (self , axis = None , dtype = None , out = None , ddof = 0 , keepdims = False ):
567
696
""" Returns the variance of the array elements, along given axis.
@@ -580,15 +709,37 @@ def strides(self):
580
709
581
710
return self ._array_obj .strides
582
711
583
- # 'sum',
712
+ def sum (self , axis = None , dtype = None , out = None , keepdims = False , initial = 0 , where = True ):
713
+ """
714
+ Returns the sum along a given axis.
715
+
716
+ .. seealso::
717
+ :obj:`dpnp.sum` for full documentation,
718
+ :meth:`dpnp.dparray.sum`
719
+
720
+ """
721
+
722
+ return dpnp .sum (self , axis , dtype , out , keepdims , initial , where )
723
+
584
724
# 'swapaxes',
585
725
# 'take',
586
726
# 'tobytes',
587
727
# 'tofile',
588
728
# 'tolist',
589
729
# 'tostring',
590
730
# 'trace',
591
- # 'transpose',
731
+
732
+ def transpose (self , * axes ):
733
+ """
734
+ Returns a view of the array with axes permuted.
735
+
736
+ .. seealso::
737
+ :obj:`dpnp.transpose` for full documentation,
738
+ :meth:`numpy.ndarray.reshape`
739
+
740
+ """
741
+
742
+ return dpnp .transpose (self , axes )
743
+
592
744
# 'var',
593
745
# 'view'
594
-
0 commit comments