0

Suppose i have a numpy array u with a given shape, a a divisor d of the total number of entries in u. How can i fastly reshape u to be shaped (something,d) ?

The case where u is just a double should be included as well -> (1,1)

The case where u is empty should become a (0,d) shaped array

1 Answer 1

1

You want to use reshape

u.reshape(-1, d)

There is no double in Python you do you mean float ?

In short :

import numpy as np

def div_reshape(arr, div):
    if arr.size == 0:
        return np.empty(shape=(0, div))
    elif arr.size == 1:
        return arr.reshape(1, 1)
    else:
        return arr.reshape(-1, d)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.