nby3shape

ssapy.compute.nby3shape(arr_)[source][source]

Reshapes or transforms an input NumPy array into a shape compatible with (n, 3).

This function takes a NumPy array and ensures it has a shape of (n, 3), where n is the number of rows. The behavior depends on the dimensionality of the input array:

  • If the input array is 1-dimensional, it reshapes it into a (1, 3) array.

  • If the input array is 2-dimensional:
    • If the second dimension already has size 3, the array is returned as-is.

    • Otherwise, the array is transposed.

Parameters:

arr (numpy.ndarray) – The input NumPy array to reshape or transform.

Returns:

The reshaped or transformed array with a shape of (n, 3).

Return type:

numpy.ndarray

Raises:

ValueError – If the input array cannot be reshaped or transformed into the desired shape.

Examples

>>> import numpy as np
>>> arr1 = np.array([1, 2, 3])
>>> nby3shape(arr1)
array([[1, 2, 3]])
>>> arr2 = np.array([[1, 2, 3], [4, 5, 6]])
>>> nby3shape(arr2)
array([[1, 2, 3],
       [4, 5, 6]])
>>> arr3 = np.array([[1, 4], [2, 5], [3, 6]])
>>> nby3shape(arr3)
array([[1, 2, 3],
       [4, 5, 6]])