Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: <incorrect processing mode wrap 'BUG: ' np.pad> #29213

Open
@debekbru

Description

@debekbru

Describe the issue:

np.pad mode wrap
at 1 : adds the last element of the sequence to the beginning and the first to the end, allowing better processing of boundary elements. result =
[[1 1 0 0 0 0 0 1 0 0 0 1 0 1 0 0 1 0 1 1 1 1]] instead of
[[0 1 0 0 0 1 1 1 0 0 0 0 0 1 1 0 1 0 1 0 0 1]]
at 2 : 2 elements are added accordingly. In fact, the expected sequence does not match the result of processing. result =
[[0 0 0 1 1 0 0 1 0 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1]] instead of
[[0 0 1 0 0 0 1 1 1 0 0 0 0 0 1 1 0 1 0 1 0 0 1 0]]

dtype='U1' or 'int' it doesn't matter ...

Reproduce the code example:

import numpy as np
def bin20_checker():
    bin20str = ['1,5,6,7,13,14,16,18']
    bin20data = np.array([list(line) for line in bin20str], dtype='U1')
    bin20mod1 = np.pad(bin20data, 1, mode='wrap')
    bin20mod2 = np.pad(bin20data, 2, mode='wrap')
    print("last element bin20str = ", bin20str[-1:]) # ['1,5,6,7,13,14,16,18']
    print("last element bin20data = ", bin20data[-1:]) # [[1 0 0 0 1 1 1 0 0 0 0 0 1 1 0 1 0 1 0 0]]
    print("last el np.pad : 1, mode='wrap' = ", bin20mod1[-1:]) # [[1 1 0 0 0 0 0 1 0 0 0 1 0 1 0 0 1 0 1 1 1 1]]
    print("last el np.pad : 2, mode='wrap' = ", bin20mod2[-1:]) # [[0 0 0 1 1 0 0 1 0 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1]]

Error message:

Python and NumPy Versions:

numpy version 2.1.3
python v3.11 , v3.13
Windows 10 pro 22H2

Runtime Environment:

No response

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions