Is there a way to validate all sizes of an input array in numpy?
I am running Python 2.7.9. I have two numpy arrays (100000 x 142 and 100000 x 20) that I want to concatenate into an array of size 1, 100000 x 162.
Below is the code I am 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 am getting the following value error:
File "C: /Users/PycharmProjects/TestProjects/M.py", line 16, in rating end = np.concatenate ([actualhhdata.T, projectedhhdata [:, 20:]], axis = 1) ValueError: all dimensions of the input array other than the concatenation axis must exactly match
I have confirmed that both arrays are 'numpy.ndarry'.
Is there a way to check the dimensions of the input array to see where I am going wrong.
Thanks in advance.
source to share
I would add a (temporary) print line before concatenate
:
actualhhdata = (actones * actualhhdata) print(acutalhhdata.T.shape, projectedhhdata[:,20:].shape) end = np.concatenate((actualhhdata.T, projectedhhdata[:, 20:]), axis=1)
For more production context, you might want to add some kind of test
eg.
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
source to share