Suppose I have a numpy array c
constructed as follows:
a = np.zeros((2,4))
b = np.zeros((2,8))
c = np.array([a,b])
I would have expected c.shape
to be (2,1)
or (2,)
but instead it is (2,2)
. Additionally, what I want to do is concatenate a column vector of ones onto a
, but by accessing it through c
in the following way:
c0 = c[0] # I would have expected this to be 'a'
np.concatenate((np.ones((c0.shape[0], 1)), c0), axis=1)
This of course doesn't work because c[0]
does not equal a
as I expected, and I get
ValueError: all the input arrays must have same number of dimensions
I need some way to have an array (or list) of pairs, each pair component being a numpy array, and I need to access the first array in the pair in order to concatenate a column vector of ones to it. My application is machine learning and my data will be coming to me in the format described, but I need to modify the data at the start in order to add a bias element to it.
EDIT: I'm using Python 2.7 and Numpy 1.8.2