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:
In [0]: import numpy as np
In [1]: foo = np.array([ ['a11'], ['a21'], ['a31'], ..., ['an1'] ])
I want to be able to access the values of the array by dereferencing one value.
In [2]: foo[0]
Out[2]: 'a11'
In [3]: foo[n]
Out[3]: 'an1'
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 foo[0][0]
or foo[0][n]
to get the same values. I could use np.transpose
to Transpose the Vector into one row, but the syntax continues to produce a 2D Numpy Array that requires 2 values to dereference: hence
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
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?
foo = np.array(['a11', 'a21', 'a31', ..., 'an1'] )
. Thenfoo[0]
'a11'
. Numpy has true n-dimensional arrays, and n can be 1. – Warren Weckesserfoo[0,0]
. – Warren Weckesser