0

I am learning neural networks and I am trying to automate some of the processes. Right now, I have code to split the dataset randomly, a 284807x31 piece. Then, I need to separate inputs and outputs, meaning I need to select the entire array until the last column and, on the other hand, select only the last column. For some reason I can't figure out how to do this properly and I am stuck at splitting and separating the set as explained above. Here's my code so far (the part that refers to this specific problem):

train, test, cv = np.vsplit(data[np.random.permutation(data.shape[0])], (6,8))

# Should select entire array except the last column
train_inputs = np.resize(train, len(train[:,1]), -1)
test_inputs = np.resize(test, len(test[:,1]), -1)
cv_inputs = np.resize(cv, len(cv[:,1]), -1)

# Should select **only** the last column.
train_outs = train[:, 30]
test_outs = test[:, 30]
cv_outs = test[:, 30]

The idea is that I'd like the machine to find the column number of the corresponding dataset and do intended resizes. The second part will select only the last column - and I am not sure if that works because the script stops before that. The error is, by the way:

Traceback (most recent call last):
  File "src/model.py", line 43, in <module>
    train_inputs = np.resize(train, len(train[:,1]), -1)
TypeError: resize() takes exactly 2 arguments (3 given)

PS: Now that I am looking at the documentation, I can see I am very far from the solution but I really can't figure it out. It's the first time I am using NumPy.

Thanks in advance.

2
  • np.resize is a rarely used function. reshape is more useful (as in stackoverflow.com/questions/41795638/…). And the index slicing as shown in the answer is very common. Maybe you are used to using resize in VBA or other languages. Commented Jan 22, 2017 at 23:51
  • I see. Thanks! I am not used to any language. Just a guy trying to learn new skills and I am searching for problems as I go. I found that solution to one of the problems but apparently was not a good solution :) Commented Jan 23, 2017 at 0:08

1 Answer 1

2

Some slicing should help:

Should select entire array except the last column

train_inputs = train[:,:-1]
test_inputs = test[:,:-1]
cv_inputs = cv[:,:-1]

and:

Should select only the last column.

train_outs = train[:,-1]
test_outs = test[:, -1]
cv_outs = test[:, -1]
Sign up to request clarification or add additional context in comments.

1 Comment

I think this solved the issue, even though I am getting another issue but that is related with other parts of the code. Thanks!

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.