2

I am trying to import this data from a csv file into a 2D array:

0
1
1
0

This is my code:

Y = np.genfromtxt("output_data.csv", delimiter=",")

I am looking for a structure like this:

[[ 0. ]
 [ 1. ]
 [ 1. ]
 [ 0. ]]

but instead it comes out like this:

[ 0.  1.  1.  0.]

As soon as I add a second column to the data it comes out the correct way. I am looking for a general solution so I don't have to program any special cases for a single column of data.

Thanks :)

0

1 Answer 1

4

Try

Y = np.loadtxt("output_data.csv", delimiter=",", ndmin=2)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.