Python Numpy - Reading elements of a Vector Numpy Array as numerical values rather than as Numpy Arrays
<p>Suppose I have a Numpy Array that has dimensions of nx1 (n rows, 1 column). My usage of this is for implementing 3D vectors as 3x1 Matrices using Numpy, but the application can be extended for nx1 Vector Matrices:</p>

<pre><code>In [0]: import numpy as np

In [1]: foo = np.array([ ['a11'], ['a21'], ['a31'], ..., ['an1'] ])
</code></pre>

<p>I want to be able to access the values of the array by dereferencing one value.</p>

<pre><code>In [2]: foo[0]
Out[2]: 'a11'

In [3]: foo[n]
Out[3]: 'an1'
</code></pre>

<p>However, by the general formatting of Numpy Arrays, a Vector array would be considered a 2D Array and would require 2 values to dereference it: I would have to use <code>foo[0][0]</code> or <code>foo[0][n]</code> to get the same values. I could use <code>np.transpose</code> to Transpose the Vector into one row, but the syntax continues to produce a 2D Numpy Array that requires 2 values to dereference: hence</p>

<pre><code>In [4]: np.transpose(foo)[0] == foo[0][0]
Out[4]: array([ True, False, False], dtype=bool)

In [5]: np.transpose(foo)[0][0] == foo[0][0]
Out[5]: True
</code></pre>

<p>This would nullify any advantage that transposing would provide. How can I access the elements of a Vector Numpy Array using only one Dereferencing Value?</p>

<p>You could use the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.tolist.html" rel="nofollow">numpy.ndarray.tolist()</a> function:</p>

<pre><code>In [1]: foo = np.array([ ['a11'], ['a21'], ['a31'] ])
In [2]: foo.tolist()
Out[2]: [['an1'], ['a2n'], ['a3n']]

In [3]: foo.tolist()[0]
Out[3]: ['an1']
</code></pre>

python arrays numpy vector dereference