patternpythonMinor
Efficient implementation of aggregating test/train data
Viewed 0 times
efficientaggregatingtraintestimplementationdata
Problem
Here is a short python snippet to ingest train data:
The variable
x_train = []
y_train = []
for x,y in train:
x_train.append(x)
y_train.append(y)
x_train = np.asarray(x_train)
y_train = np.asarray(y_train)The variable
train is a list of 60000 (x,y) tuples.Solution
How about:
Which uses only numpy functions and should be a bit faster than your implementation using intermediate lists.
x_train, y_train = np.hsplit(np.asarray(train), 2)Which uses only numpy functions and should be a bit faster than your implementation using intermediate lists.
Code Snippets
x_train, y_train = np.hsplit(np.asarray(train), 2)Context
StackExchange Code Review Q#140709, answer score: 3
Revisions (0)
No revisions yet.