0

i am not able to reshape the dimensions of the this array:

Shape of array:
(1, 81539)

Array:
[[ 906.78302002   10.00976562   23.4375     ... 4594.27587891
49.99263      41.85557556]]

i am using

reshape(-1,36)

So there should be 36 columns and the needed amount of rows to store all the data from the array.

Sidenote: i am new to python

import pandas as pd
import numpy as np


trainData_temp = pd.read_csv('data/trainData.csv', sep=';')

numArray = np.array(trainData_temp.values).transpose()
print('Shape of array:')
print(numArray.shape)
print('Array:')
print(numArray)

numArray.reshape(-1, 36)
print(numArray)


Results:

Traceback (most recent call last):
Shape of array:
(1, 81539)
Array:
[[ 906.78302002   10.00976562   23.4375     ... 4594.27587891
49.99263      41.85557556]]

File "C:/Users/Timo/PycharmProjects/aimlHamelnProj2/csvModify.py", line 18, 
in <module>
numArray.reshape(-1, 36)
ValueError: cannot reshape array of size 81539 into shape (36)
3
  • Possible duplicate of Using reshape in Python to reshape an array Commented Jun 19, 2019 at 12:18
  • 4
    I would say that your problem is, that 81539 is not divisible by 36. Commented Jun 19, 2019 at 12:21
  • You are right, the first value is missing. I hope this is the problem. Commented Jun 19, 2019 at 12:28

2 Answers 2

1

That is properly because you only can reshape an array into a matrix with the same number of elements.

For example:

import numpy

array = np.random.rand(3,3)
array.reshape(-1,3)

results in a 3x3 matrix, but

array = np.random.rand(3,3)
array.reshape(-1,5)

would give you the same typ of error.

Sign up to request clarification or add additional context in comments.

Comments

0

Well, the problem was, that the first value of the csv file has been interpreted as the name of the column. So there was one value missing..

Thanks all for your help!

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.