When I try to work with 1D arrays - i get IndexError: too many indices for array
kzorina opened this issue · 2 comments
kzorina commented
Am I doing something wrong, or code just designed for 2D arrays only?
Here is the code and the error
X = np.random.poisson(2, 400)
tr, te = train_test_split(X, test_size=0.8)
V_opt, gw_opt, opt_info = gof.GaussFSSD.optimize_auto_init(p, data.Data(tr), J, **opts)
IndexError Traceback (most recent call last)
<ipython-input-40-380dbe5289fc> in <module>
14 # make sure to give tr (NOT te).
15 # do the optimization with the options in opts.
---> 16 V_opt, gw_opt, opt_info = gof.GaussFSSD.optimize_auto_init(p, data.Data(tr), J, **opts)
~\AppData\Local\Continuum\anaconda3\envs\ml_python36\lib\site-packages\kgof\goftest.py in optimize_auto_init(p, dat, J, **ops)
499 n_gwidth_cand = 5
500 gwidth_factors = 2.0**np.linspace(-3, 3, n_gwidth_cand)
--> 501 med2 = util.meddistance(X, 1000)**2
502
503 k = kernel.KGauss(med2*2)
~\AppData\Local\Continuum\anaconda3\envs\ml_python36\lib\site-packages\kgof\util.py in meddistance(X, subsample, mean_on_fail)
146 np.random.set_state(rand_state)
147 # recursion just one
--> 148 return meddistance(X[ind, :], None, mean_on_fail)
149
150
IndexError: too many indices for array
wittawatj commented
data.Data(Y)
assumes that Y is an n x d numpy array. After creating X with np.random.poisson(...), try adding this line
X = X[:, np.newaxis]
Does it work?
kzorina commented
It worked! Thanks a lot for explanation and such quick answer!