0

I have a pandas DataFrame that i transform to numpy array like this

  training_set = dataset_train.iloc[:, 1:2].values

  X_train = []
  for i in range(60, 1258):
      X_train.append(training_set[i-60:i, 0])
      y_train.append(training_set[i, 0])

  X1_train = np.array(X1_train)

X1_train.shape = (1198, 60)

after a create a 3d array

X1_train = np.reshape(X1_train, (X1_train.shape[0], X1_train.shape[1] , 1))

X2_train.shape = (1198,0)

now when a try to add a new input x2_train.shape[0], x2_train.shape[1] in my array and I am blocked

I tried several things like this

X1_train = np.reshape(X1_train, ([X1_train.shape[0], X1_train.shape[1], X2_train.shape[0], X2_train.shape[1]] , 1))

X1_train = np.reshape(X1_train, (X2_train.shape[0], X2_train.shape[1] , 1))

i have this error when a run my code

File "/anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 257, in reshape
    return _wrapfunc(a, 'reshape', newshape, order=order)

  File "/anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 62, in _wrapfunc
    return _wrapit(obj, method, *args, **kwds)

  File "/anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 42, in _wrapit
    result = getattr(asarray(obj), method)(*args, **kwds)

TypeError: 'list' object cannot be interpreted as an integer

and the numpy doc is not very clear

4
  • How did you try to add the new input? Commented Mar 10, 2018 at 17:51
  • X1_train = np.reshape(X1_train, ([X1_train.shape[0], X1_train.shape[1], X2_train.shape[0], X2_train.shape[1]] , 1)) X1_train = np.reshape(X1_train, (X2_train.shape[0], X2_train.shape[1] , 1)) X1_train = np.reshape(X1_train, ([X1_train.shape[0], [X2_train.shape[0], [X1_train.shape[1] , [X2_train.shape[1] , 1)) Commented Mar 10, 2018 at 17:55
  • What are the errors that you get? And what is the shape of X2_train? Commented Mar 10, 2018 at 18:20
  • X2_train.shape is the same of X1_train and my error is ` File "/anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 257, in reshape return _wrapfunc(a, 'reshape', newshape, order=order) File "/anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 62, in _wrapfunc return _wrapit(obj, method, *args, **kwds) File "/anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 42, in _wrapit result = getattr(asarray(obj), method)(*args, **kwds) TypeError: 'list' object cannot be interpreted as an integer ` Commented Mar 10, 2018 at 18:32

2 Answers 2

1

your response is good but you are not forgetting to reshape your array

you can remove this

  X1_train = np.reshape(X1_train, (X1_train.shape[0], X1_train.shape[1] , 1))

 X2_train = np.reshape(X2_train, (X2_train.shape[0], X2_train.shape[1] , 1))


new_train  = np.dstack((X1_train, X2_train))

and just write your code like this

new_train  = np.dstack((X1_train, X2_train))
Sign up to request clarification or add additional context in comments.

Comments

0

The answer is replace the line

X1_train = np.reshape(X1_train, (X1_train.shape[0], X1_train.shape[1] , 1))

and replace by

X1_train = np.reshape(X1_train, (X1_train.shape[0], X1_train.shape[1] , 1))

 X2_train = np.reshape(X2_train, (X2_train.shape[0], X2_train.shape[1] , 1))


new_train  = np.dstack((X1_train, X2_train))

this a the 2 dimension to 3d array

new_train.shape = (1198, 60, 2)

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.