3
votes

I'm running Python 2.7.9. I have two numpy arrays (100000 x 142 and 100000 x 20) that I want to concatenate into 1, 100000 x 162 array.

The following is the code I'm running:

import numpy as np
import pandas as pd

def ratingtrueup():
    actones = np.ones((100000, 20), dtype='f8', order='C')
    actualhhdata = np.array(pd.read_csv
                           ('C:/Users/Desktop/2015actualhhrating.csv', index_col=None, header=None, sep=','))
    projectedhhdata = np.array(pd.read_csv
                           ('C:/Users/Desktop/2015projectedhhrating.csv', index_col=None, header=None, sep=','))
    adjfctr = round(1 + ((actualhhdata.mean() - projectedhhdata.mean()) / projectedhhdata.mean()), 5)
    projectedhhdata = (adjfctr * projectedhhdata)
    actualhhdata = (actones * actualhhdata)
    end = np.concatenate((actualhhdata.T, projectedhhdata[:, 20:]), axis=1)
ratingtrueup()

I get the following value error:

File "C:/Users/PycharmProjects/TestProjects/M.py", line 16, in ratingtrueup end = np.concatenate([actualhhdata.T, projectedhhdata[:, 20:]], axis=1) ValueError: all the input array dimensions except for the concatenation axis must match exactly

I've confirmed that both arrays are 'numpy.ndarry'.

Is there a way to I check the dimensions of the input array to see where I'm going wrong.

Thank you in advance.

1
you can use the attribute ndim, and if you want to guarantee a certain dimension np.atleast_1d, np.atleast_2d or np.atleast_3d - Saullo G. P. Castro
ndim gives you the number of dimensions. you want the shape. - mariotomo
if just before the concatenate you do print actualhhdata.shape, projectedhhdata[:, 20:].shape it should clear things up. - tom10

1 Answers

2
votes

I would add a (temporary) print line right before the concatenate:

actualhhdata = (actones * actualhhdata)
print(acutalhhdata.T.shape, projectedhhdata[:,20:].shape)
end = np.concatenate((actualhhdata.T, projectedhhdata[:, 20:]), axis=1)

For more of a production context, you might want to add some sort of test

e.g.

x,y=np.ones((100,20)),np.zeros((100,10))
assert x.shape[0]==y.shape[0], (x.shape,y.shape)
np.concatenate([x,y],axis=1).shape