@@ -2504,14 +2504,17 @@ def pad(array, pad_width, mode="constant", **kwargs):
2504
2504
----------
2505
2505
array : {dpnp.ndarray, usm_ndarray}
2506
2506
The array of rank ``N`` to pad.
2507
- pad_width : {sequence, array_like, int}
2507
+ pad_width : {sequence, array_like, int, dict }
2508
2508
Number of values padded to the edges of each axis.
2509
2509
``((before_1, after_1), ... (before_N, after_N))`` unique pad widths
2510
2510
for each axis.
2511
2511
``(before, after)`` or ``((before, after),)`` yields same before
2512
2512
and after pad for each axis.
2513
2513
``(pad,)`` or ``int`` is a shortcut for ``before = after = pad`` width
2514
2514
for all axes.
2515
+ If a dictionary, each key is an axis and its corresponding value is an
2516
+ integer or a pair of integers describing the padding ``(before, after)``
2517
+ or ``pad`` width for that axis.
2515
2518
mode : {str, function}, optional
2516
2519
One of the following string values or a user supplied function.
2517
2520
@@ -2694,6 +2697,26 @@ def pad(array, pad_width, mode="constant", **kwargs):
2694
2697
[100, 100, 100, 100, 100, 100, 100],
2695
2698
[100, 100, 100, 100, 100, 100, 100]])
2696
2699
2700
+ >>> a = np.arange(1, 7).reshape(2, 3)
2701
+ >>> np.pad(a, {1: (1, 2)})
2702
+ array([[0, 1, 2, 3, 0, 0],
2703
+ [0, 4, 5, 6, 0, 0]])
2704
+ >>> np.pad(a, {-1: 2})
2705
+ array([[0, 0, 1, 2, 3, 0, 0],
2706
+ [0, 0, 4, 5, 6, 0, 0]])
2707
+ >>> np.pad(a, {0: (3, 0)})
2708
+ array([[0, 0, 0],
2709
+ [0, 0, 0],
2710
+ [0, 0, 0],
2711
+ [1, 2, 3],
2712
+ [4, 5, 6]])
2713
+ >>> np.pad(a, {0: (3, 0), 1: 2})
2714
+ array([[0, 0, 0, 0, 0, 0, 0],
2715
+ [0, 0, 0, 0, 0, 0, 0],
2716
+ [0, 0, 0, 0, 0, 0, 0],
2717
+ [0, 0, 1, 2, 3, 0, 0],
2718
+ [0, 0, 4, 5, 6, 0, 0]])
2719
+
2697
2720
"""
2698
2721
2699
2722
dpnp .check_supported_arrays_type (array )
0 commit comments