0

I have a numpy array of shape arr.shape: (416809, )

which has:

arr[0].shape:
(300,)

and I whish to reshape to: (416809, 300)

I was searching at the documentation but I was unable to find a solution.

Any help would be grateful!

Thanx!

6
  • See this SO question just a few minutes ago: stackoverflow.com/questions/63218534/…. How was your array created? Do all the component arrays have the same shape? Commented Aug 2, 2020 at 16:54
  • Mine is different. I have 416809 arrays of 300 dimensions and I want to make them. (416809, 300) so 2D Commented Aug 2, 2020 at 16:56
  • Does np.stack(arr) work? Commented Aug 2, 2020 at 17:01
  • No, it makes a tuple of: (416809, 300). The tuple has just these 2 integers. Not the numpy arrays Commented Aug 2, 2020 at 17:10
  • (416809, 300) is the shape tuple, not the array produced by stack. Commented Aug 2, 2020 at 17:13

1 Answer 1

1

To convert the shape of a NumPy array ndarray, use the reshape() method of ndarray or the numpy.reshape() function.

Here is an example for your reference

import numpy as np

a = np.arange(24)

print(a)
# [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23]

print(a.shape)
# (24,)

a_4_6 = a.reshape([4, 6])

print(a_4_6)
# [[ 0  1  2  3  4  5]
#  [ 6  7  8  9 10 11]
#  [12 13 14 15 16 17]
#  [18 19 20 21 22 23]]
Sign up to request clarification or add additional context in comments.

1 Comment

This works only when the values of the array are just Integers. In my situation the values of the arrays are numpy arrays of size (300, ). So the reshape method wont work like that.

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.