Skip to content

ENH: ndarray.T2 for 2D transpose. #7495

@toddrjen

Description

@toddrjen

When you try to transpose a 1D array, it does nothing. This is the correct behavior, since it transposing a 1D array is meaningless. However, this can often lead to unexpected errors since this is rarely what you want. You can convert the array to 2D, using np.atleast_2d or arr[None], but this makes simple linear algebra computations more difficult.

I propose adding an argument to transpose, perhaps called expand or expanddim, which if True (it is False by default) will force the array to be at least 2D. A shortcut property, ndarray.T2, would be the same as ndarray.transpose(True).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions