Skip to content

Replace np.resize with np.reshape to preserve label integrity #22

Description

@SaFE-APIOpt

DDPG/ddpg.py

Line 66 in 18825ee

y_batch = np.resize(y_batch,[BATCH_SIZE,1])

Current code:
y_batch = np.resize(y_batch, [BATCH_SIZE, 1])
Proposed replacement:
y_batch = np.reshape(y_batch, [BATCH_SIZE, 1])
np.reshape changes the view/shape of an array only if the element count matches. If not compatible, it raises an error — making issues explicit and avoiding silent bugs.

np.resize will always return the requested shape. If the target shape has more elements, it repeats data to fill it; if fewer, it truncates data. This can corrupt labels in y_batch without warning.

Performance: reshape is faster and more memory-efficient because it typically returns a view instead of creating new data.

Robustness: For supervised learning, label arrays (y_batch) should not be silently duplicated or truncated. Using reshape ensures consistency and correctness.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions