Skip to content

numpy/append-flattens

Pack Severity Fix Versions
NumPy error none, edit by hand All versions

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.

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.

See all rules in the NumPy pack.