0

I'm trying to import the below data (excel file) into a 2D numpy array

x1 | x2
12 | 56
34 | 89
43 | 10
34 | 11

My Python code:

spreadsheet = 'zone.xlsx'
data = pd.read_excel(spreadsheet)
x = data['x1'].values
y = data['x2'].values

x_train = np.concatenate((x,y))

The problem is that the output for x_train is [12, 34, 43, 34, 56, 89, 10, 11] and I would like to get the following output:

[[12, 56], [34, 56], [43,10], [34,11]]
4
  • have u tried concatenating without the .values Commented Nov 30, 2020 at 14:10
  • Yes. When I check the .shape, the result is (8,). I want to get (4, 2,2) as .shape Commented Nov 30, 2020 at 14:12
  • data.values or data.to_numpy()? Commented Nov 30, 2020 at 14:17
  • data.values, but It works now. Check ombk's answeer Commented Nov 30, 2020 at 14:18

1 Answer 1

1
x = np.array([1,2,3]).reshape(-1,1)
y= np.array([2,3,4]).reshape(-1,1)
np.concatenate([x,y],axis=1)

#output

array([[1, 2],
       [2, 3],
       [3, 4]])
np.concatenate([x,y],axis=1).tolist()
[[1, 2], [2, 3], [3, 4]]
Sign up to request clarification or add additional context in comments.

3 Comments

It worked, first I transformed my Python label into a numpy array, then the reshape method worked. Thank you
@Viorel great ^_^
@Viorel accept answer to remove it from unanswered questions queue! 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.