Skip to content

numpy/append-flattens

Rule append-flattens
Pack NumPy
Severity error
Fix none, edit by hand
Library versions every version

Without axis, np.append and np.insert flatten both arrays, so a row you add becomes loose values in one dimension. Pass axis=0 to add rows or axis=1 to add columns.

grown = np.append(m, [[5, 5]])
grown = np.append(m, [[5, 5]], axis=0)

The rule reports np.append(m, [[5, 5]]) and np.insert(m, 0, [[5, 5]]) without axis. Both calls flatten the array, so the row becomes separate values in one dimension.

xpd has no automatic fix, so make the change by hand.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

Without axis, $F flattens both arrays, so the row becomes loose values in a one dimensional result. Pass axis=0 to add rows or axis=1 to add columns.

Browse the other rules of the NumPy pack.