Reading file as array
<p>I have a <em>cvs</em> file which has three columns of numbers up to three digits each:</p>

<pre><code>1 0 0
2 0 0
3 0 0
4 0 0
5 0 0
6 0 0
7 0 0
8 0 0
9 0 0
10 0 0
11 0 0
</code></pre>

<p>I want to read the columns separately and be able to use them as arrays with:</p>

<pre><code>data = np.loadtxt('file.csv')
x = data[:, 0]
y = data[:, 1]
</code></pre>

<p>But I'm getting:</p>

<pre><code>X = np.array(X, dtype)
ValueError: setting an array element with a sequence.
</code></pre>

<p>If instead I use the line <code>x,y = np.loadtxt('Beamprofile.txt', usecols=(0,1), unpack=True)</code> the error disappears but <em>x</em> and <em>y</em> don't seem to be read correctly in further operations.</p>

<p>With your sample:</p>

<pre><code>In [1]: data=np.loadtxt('stack39174768.txt')
In [2]: data
Out[2]: 
array([[  1.,   0.,   0.],
       [  2.,   0.,   0.],
       [  3.,   0.,   0.],
       [  4.,   0.,   0.],
       [  5.,   0.,   0.],
       [  6.,   0.,   0.],
       [  7.,   0.,   0.],
       [  8.,   0.,   0.],
       [  9.,   0.,   0.],
       [ 10.,   0.,   0.],
       [ 11.,   0.,   0.]])
In [3]: x=data[:,0]
In [4]: y=data[:,1]
In [5]: x
Out[5]: array([  1.,   2.,   3.,   4.,   5.,   6.,   7.,   8.,   9.,  10.,  11.])
In [6]: y
Out[6]: array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])
</code></pre>

<p>Where's the problem?  Is there's something about the file that we're not seeing in the clip?</p>

<pre><code>In [8]: x,y = np.loadtxt('stack39174768.txt', usecols=(0,1), unpack=True)
</code></pre>

<p>produces the same <code>x</code> and <code>y</code>.</p>

<p>I asked about shape and dtype</p>

<pre><code>In [11]: data.shape
Out[11]: (11, 3)
In [12]: data.dtype
Out[12]: dtype('float64')
</code></pre>

<p>I like <code>np.genfromtxt</code> a little better, but in this case it produces the same <code>data</code>.</p>

python arrays numpy