I don't know why this probelm , all the time the varaiable of parameters out of range , and now also the problem is for code and give me this eroor object of type 'Bounds' has no len():
(I hope i can find the error in my code or find other good code for using bounds of variabels)
Traceback (most recent call last):
File "./trigger_SLQ.py", line 160, in <module>
main()
File "./trigger_SLQ.py", line 156, in main
opt(x0)
File "./trigger_SLQ.py", line 148, in opt
res = basinhopping(rmse, x0, minimizer_kwargs=minimizer_kwargs, T=10000.0,
stepsize=1.0, niter=100, niter_success=200, accept_test=bounds)
File "/usr/lib/python3/dist-packages/scipy/optimize/_basinhopping.py", line
611, in basinhopping
accept_tests, disp=disp)
File "/usr/lib/python3/dist-packages/scipy/optimize/_basinhopping.py", line
72, in __init__
minres = minimizer(self.x)
File "/usr/lib/python3/dist-packages/scipy/optimize/_basinhopping.py", line
280, in __call__
return self.minimizer(self.func, x0, **self.kwargs)
File "/usr/lib/python3/dist-packages/scipy/optimize/_minimize.py", line 455,
in minimize
constraints, callback=callback, **options)
File "/usr/lib/python3/dist-packages/scipy/optimize/slsqp.py", line 329, in
_minimize_slsqp
if bounds is None or len(bounds) == 0:
TypeError: object of type 'Bounds' has no len()
I use this code
b0 = (5, 95)
b1 = (0.10, 0.95)
b2= (2, 8)
bounds=((5, 95), (0.10, 0.95), (2, 8))
class Bounds(object):
def __init__(self, xmax=[0,0,2], xmin=[100,0.100,8], stepsize=0.01):
self.xmax = np.array(xmax)
self.xmin = np.array(xmin)
self.stepsize = stepsize
def __call__(self, x):
min_step = np.maximum(self.xmin - x, -self.stepsize)
max_step = np.minimum(self.xmax - x, self.stepsize)
random_step = np.random.uniform(low=min_step, high=max_step, size=x.shape)
xnew = x + random_step
return xnew
bounded_step = Bounds(np.array([b[0] for b in bounds]), np.array([b[1]
for b in bounds]), np.array([b[2] for b in bounds]))
def opt(x0):
bounds = Bounds()
minimizer_kwargs = {'method':'SLSQP', 'bounds':bounds,'options':{'maxiter':1000, 'ftol':1e-2, 'eps':1e-2},}
res = basinhopping(rmse, x0, minimizer_kwargs=minimizer_kwargs, T=10000.0, stepsize=1.0, niter=100, niter_success=200, accept_test=mybounds)
print(res.x)
return res.x
def main():
x0 = np.array((50.0, 0.50, 5.0)) # initial guess
opt(x0)
if __name__ == "__main__":
main()
Related
I am trying to create a program that takes a model of differential equations as input, and shows its evolution with time in an animated/slider graph. For now, im just using the SIR model of infectious disease spread but I plan to make it so that it can user input differential equations upto models with 5 equations. I seem to have no problem in making a normal graph using plt.plot, but when i try to make the graph dynamic/interactive, it gives me similar errors:
'''
enter total population: 10000
enter number of infected people: 20
enter number of recovered people: 0
Traceback (most recent call last):
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\cbook\__init__.py", line 287, in process
func(*args, **kwargs)
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\widgets.py", line 585, in <lambda>
return self._observers.connect('changed', lambda val: func(val))
File "e:\Python\bio3636\exam2.py", line 45, in update
ax.plot(t1, sir1)
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\axes\_axes.py", line 1632, in plot
lines = [*self._get_lines(*args, data=data, **kwargs)]
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\axes\_base.py", line 312, in __call__
yield from self._plot_args(this, kwargs)
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\axes\_base.py", line 498, in _plot_args
raise ValueError(f"x and y must have same first dimension, but "
ValueError: x and y must have same first dimension, but have shapes (1,) and (1000, 3)
this ^ is for when i use a slider object
enter total population: 10000
enter number of infected people: 20
enter number of recovered people: 0
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 814, in callit
func(*args)
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\backends\_backend_tk.py", line 252, in idle_draw
self.draw()
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\backends\backend_tkagg.py", line 9, in draw
super().draw()
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\backends\backend_agg.py", line 436, in draw
self.figure.draw(self.renderer)
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\artist.py", line 73, in draw_wrapper
result = draw(artist, renderer, *args, **kwargs)
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\artist.py", line 50, in draw_wrapper
return draw(artist, renderer)
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\figure.py", line 2837, in draw
mimage._draw_list_compositing_images(
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\image.py", line 132, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\artist.py", line 50, in draw_wrapper
return draw(artist, renderer)
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\axes\_base.py", line 3091, in draw
mimage._draw_list_compositing_images(
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\image.py", line 132, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\artist.py", line 50, in draw_wrapper
return draw(artist, renderer)
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\lines.py", line 732, in draw
self.recache()
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\lines.py", line 661, in recache
self._xy = np.column_stack(np.broadcast_arrays(x, y)).astype(float)
File "<__array_function__ internals>", line 180, in broadcast_arrays
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\numpy\lib\stride_tricks.py", line 540, in broadcast_arrays
shape = _broadcast_shape(*args)
File "C:\Users\Avi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\numpy\lib\stride_tricks.py", line 422, in _broadcast_shape
b = np.broadcast(*args[:32])
ValueError: shape mismatch: objects cannot be broadcast to a single shape. Mismatch is between arg 0 with shape (1000,) and arg 1 with shape (3000,).
this is for animated graph.
here's my code:
#Plotting a dynamic graph to observe time evolution of a diffn eq. Furthermore,
# plot the points in an excel file for easy access data.
from cProfile import label
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
import matplotlib.animation as animation
from matplotlib.widgets import Slider
#t1 = float(input('enter starting time: '))
#t2 = float(input('enter ending time: '))
#d = float(input('enter divisions: '))
t = np.linspace(0, 100, 1000)
ttest = [a for a in range(0,1000)]
et =[]
for i in ttest:
et.append(i/10)
def model(z,t,k1,k2):
s,i,r = z
dsdt = -k1*s*i
didt = (k1*s*i) - k2*i
drdt = k2*i
return [dsdt, didt, drdt]
p = int(input('enter total population: '))
i = int(input('enter number of infected people: '))
r = int(input('enter number of recovered people: '))
z0 = [p-i, i, r]
k1 = 0.5
k2 = 1/3
sir = odeint(model, z0, t, args = (k1,k2))
fig = plt.figure()
ax = fig.add_subplot(111)
#fig.subplots_adjust(bottom = 0.2, top = 0.75)
#s = fig.add_axes([0.3, 0.92, 0.4, 0.05])
#s.spines['top'].set_visible(True)
#s.spines['right'].set_visible(True)
#sl = Slider(ax = s, label = 'time', valmin = 0, valmax = 100, valinit = 100 )
f_d = ax.plot([], [])[0]
#def update(val):
# t1 = sl.val
# sir1 = sir
#ax.plot(t1, sir1)
#fig.canvas.draw_idle()
#sl.on_changed(update)
def ani(i):
x = t
y = sir
f_d.set_data(x,y)
a = animation.FuncAnimation(fig = fig, func = ani, frames = range(len(t)), interval = 500)
plt.show()
any help would be appreciated, thanks.
i was trying to make curve as follows:
x = all_dat['rcs']
y = all_dat['Mean_Range']
xnew = np.linspace(x.min(), x.max(), 200)
cubic_interploation_model = interp1d(x, y, kind = "cubic")
y_=cubic_interploation_model(xnew)
pl.plot(xnew , y_)
but i was not getting a plot and end with an error:
Traceback (most recent call last):
File "C:\Users\xxx\PycharmProjects\pythonProject1\seq_2_final.py", line 268, in <module>
plot_alldata(df_all,p2)
File "C:\Users\xxx\PycharmProjects\pythonProject1\seq_2_final.py", line 201, in plot_alldata
cubic_interploation_model = interp1d(x, y, kind = "cubic")
File "C:\Users\xxx\PycharmProjects\pythonProject1\venv\lib\site-packages\scipy\interpolate\_interpolate.py", line 564, in __init__
self._spline = make_interp_spline(xx, yy, k=order,
File "C:\Users\xxx\PycharmProjects\pythonProject1\venv\lib\site-packages\scipy\interpolate\_bsplines.py", line 1295, in make_interp_spline
raise ValueError("Expect x to not have duplicates")
ValueError: Expect x to not have duplicates
Process finished with exit code 1
How to solve this issue?
def integrate_ode(ode,u0,T):
sol=solve_ivp(ode,T,u0)
return sol.y[:,-1]
def phase(ode,u0):
return ode(0,u0)[0] #dx/dt(0)
def shooting(ode,U):
print(len(U))
u0=U[0:-1]
#print(u0)
T=U[-1]
#print(T)
G=np.concatenate((integrate_ode(ode,u0,T)-u0,phase(ode,u0)))
return G
To get the solutions I'm using:
fsolve(lambda U:shooting(ode1,U),...(initial conditions))
I'm getting this error:
IndexError: invalid index to scalar variable.
Here is my full traceback:
Traceback (most recent call last):
"...Python\workweek16.py", line 62, in <module>
G=fsolve(lambda U:shooting(ode1,U),(0,0))
File "C:\Users\tmara\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\scipy\optimize\minpack.py", line 160, in fsolve
res = _root_hybr(func, x0, args, jac=fprime, **options)
File "C:\Users\tmara\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\scipy\optimize\minpack.py", line 226, in _root_hybr
shape, dtype = _check_func('fsolve', 'func', func, x0, args, n, (n,))
File "C:\Users\tmara\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\scipy\optimize\minpack.py", line 24, in _check_func
res = atleast_1d(thefunc(*((x0[:numinputs],) + args)))
File "...Python\workweek16.py", line 62, in <lambda>
G=fsolve(lambda U:shooting(ode1,U),(0,0))
File "...Python\workweek16.py", line 51, in shooting
G=np.concatenate((integrate_ode(ode,u0,T)-u0,phase(ode,u0)))
File "...Python\workweek16.py", line 40, in integrate_ode
sol=solve_ivp(ode,T,u0)
File "C:\Users\tmara\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\scipy\integrate\_ivp\ivp.py", line 508, in solve_ivp
t0, tf = float(t_span[0]), float(t_span[1])
IndexError: invalid index to scalar variable.
Does anyone know what to do?
The t_span argument for solve_ivp needs to actually be a time span. So replace T there with [0,T].
I am using Python 3.7 and Numpy 1.18.5.
I tried to run the following code:
import numpy as np
def rot(direc,ang):
c=np.cos(ang)
s=np.sin(ang)
if direc=='x':
R = np.block([[1, 0, 0],[0, c, -s],[0, s, c]])
elif direc=='y':
R = np.block([[c, 0, s],[0, 1, 0],[-s, 0, c]])
elif direc=='z':
R = np.block([[c, -s, 0],[s, c, 0],[0, 0, 1]])
else:
'Direction not recognized.'
return R
def Hjac(fun,x,reg):
class HJAC():
def __init__(self):
self.z = np.spacing(shape=(6,1))
self.A = np.spacing(shape=(6,10))
z = np.vectorize(fun)
n = np.size(x)
m = np.size(z)
A = np.empty(shape=(m,n))
h = n*np.spacing(1)
ns = range(0,n)
for k in ns:
x1 = x;
x1[k] = x1[k]+h*1j
A[:,k] = np.imag(z(x1,reg))/h
HJacobi = HJAC()
HJacobi.z = z
HJacobi.A = A
return HJacobi
def fun(x,reg):
R = rot('x',reg[1])
f = np.dot(R,x*reg)
return f
x = np.random.rand(3,1)
reg = np.random.rand(3,1)
H = Hjac(fun,x,reg)
I am trying to obtain a jacobian of a function 'fun' with respect to a vector 'x'.
But I got the following error message:
runfile('C:/Users/2JY/Documents/Python/temp.py', wdir='C:/Users/2JY/Documents/Python')
C:/Users/2JY/Documents/Python/temp.py:32: ComplexWarning: Casting complex values to real discards the imaginary part
x1[k] = x1[k]+h*1j
Traceback (most recent call last):
File "<ipython-input-1-8907a67fa932>", line 1, in <module>
runfile('C:/Users/2JY/Documents/Python/temp.py', wdir='C:/Users/2JY/Documents/Python')
File "C:\Users\2JY\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
execfile(filename, namespace)
File "C:\Users\2JY\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/2JY/Documents/Python/temp.py", line 50, in <module>
H = Hjac(fun,x,reg)
File "C:/Users/2JY/Documents/Python/temp.py", line 33, in Hjac
A[:,k] = np.imag(z(x1,reg))/h
File "C:\Users\2JY\Anaconda3\lib\site-packages\numpy\lib\function_base.py", line 2091, in __call__
return self._vectorize_call(func=func, args=vargs)
File "C:\Users\2JY\Anaconda3\lib\site-packages\numpy\lib\function_base.py", line 2161, in _vectorize_call
ufunc, otypes = self._get_ufunc_and_otypes(func=func, args=args)
File "C:\Users\2JY\Anaconda3\lib\site-packages\numpy\lib\function_base.py", line 2121, in _get_ufunc_and_otypes
outputs = func(*inputs)
File "C:/Users/2JY/Documents/Python/temp.py", line 43, in fun
R = rot('x',reg[1])
IndexError: invalid index to scalar variable.
I changed def fun(x,reg) as:
def fun(x,reg):
ang1 = reg[1]
R = rot('x',ang1)
f = np.dot(R,x*reg)
return f
and I got the following error message:
File "C:/Users/2JY/Documents/Python/temp.py", line 43, in fun
ang1 = reg[1]
IndexError: invalid index to scalar variable.
I can't understand why this kind of error happened.
I would really appreciate any answer to solve this problem.
Thank you.
I am trying to run an a code in Python for self-organizing map (SOM), which uses TensorFlow. I got the code from here, but when I run it, I get an error:
Error: Argument must be a dense tensor: range(2, 3) - got shape 1,
but wanted []
I think the code relevant is:
s = SOM( (3,), 30, num_training, sess )
and then:
class SOM:
def __init__(self, input_shape, map_size_n, num_expected_iterations, session):
input_shape = tuple([i for i in input_shape if i is not None])
or:
def initialize_graph(self):
self.weights = tf.Variable( tf.random_uniform((self.n*self.n, )+self.input_shape, 0.0, 1.0) )
self.input_placeholder = tf.placeholder(tf.float32, (None,)+self.input_shape)
self.current_iteration = tf.placeholder(tf.float32)
## Compute the current iteration's neighborhood sigma and learning rate alpha:
self.sigma_tmp = self.sigma * tf.exp( - self.current_iteration/self.timeconst_sigma )
self.sigma2 = 2.0*tf.multiply(self.sigma_tmp, self.sigma_tmp)
self.alpha_tmp = self.alpha * tf.exp( - self.current_iteration/self.timeconst_alpha )
self.input_placeholder_ = tf.expand_dims(self.input_placeholder, 1)
self.input_placeholder_ = tf.tile(self.input_placeholder_, (1,self.n*self.n,1) )
self.diff = self.input_placeholder_ - self.weights
self.diff_sq = tf.square(self.diff)
self.diff_sum = tf.reduce_sum( self.diff_sq, axis=range(2, 2+len(self.input_shape)) )
# Get the index of the best matching unit
self.bmu_index = tf.argmin(self.diff_sum, 1)
self.bmu_dist = tf.reduce_min(self.diff_sum, 1)
self.bmu_activity = tf.exp( -self.bmu_dist/self.sigma_act )
self.diff = tf.squeeze(self.diff)
self.diff_2 = tf.placeholder(tf.float32, (self.n*self.n,)+self.input_shape)
self.dist_sliced = tf.placeholder(tf.float32, (self.n*self.n,))
self.distances = tf.exp(-self.dist_sliced / self.sigma2 )
self.lr_times_neigh = tf.multiply( self.alpha_tmp, self.distances )
for i in range(len(self.input_shape)):
self.lr_times_neigh = tf.expand_dims(self.lr_times_neigh, -1)
self.lr_times_neigh = tf.tile(self.lr_times_neigh, (1,)+self.input_shape )
self.delta_w = self.lr_times_neigh * self.diff_2
self.update_weights = tf.assign_add(self.weights, self.delta_w)
The whole error message is:
Traceback (most recent call last): File
"C:\Users\jakub\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py",
line 491, in apply_op
preferred_dtype=default_dtype) File "C:\Users\jakub\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\ops.py",
line 704, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File
"C:\Users\jakub\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\constant_op.py",
line 113, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name) File "C:\Users\jakub\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\constant_op.py",
line 102, in constant
tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape)) File
"C:\Users\jakub\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\tensor_util.py",
line 379, in make_tensor_proto
_GetDenseDimensions(values))) ValueError: Argument must be a dense tensor: range(2, 3) - got shape 1, but wanted [].
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\jakub\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py",
line 505, in apply_op
values, as_ref=input_arg.is_ref).dtype.name File "C:\Users\jakub\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\ops.py",
line 704, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File
"C:\Users\jakub\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\constant_op.py",
line 113, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name) File "C:\Users\jakub\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\constant_op.py",
line 102, in constant
tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape)) File
"C:\Users\jakub\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\tensor_util.py",
line 379, in make_tensor_proto
_GetDenseDimensions(values))) ValueError: Argument must be a dense tensor: range(2, 3) - got shape 1, but wanted [].
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\jakub\OneDrive\UTP\SztucznaInteligencja\SOM\SOM2.py", line
148, in
s = SOM( (3,), 30, num_training, sess ) File "C:\Users\jakub\OneDrive\UTP\SztucznaInteligencja\SOM\SOM2.py", line
51, in init
self.initialize_graph() File "C:\Users\jakub\OneDrive\UTP\SztucznaInteligencja\SOM\SOM2.py", line
76, in initialize_graph
self.diff_sum = tf.reduce_sum( self.diff_sq, axis=range(2, 2+len(self.input_shape)) ) File
"C:\Users\jakub\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\ops\math_ops.py",
line 1236, in reduce_sum
name=name) File "C:\Users\jakub\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\ops\gen_math_ops.py",
line 2656, in _sum
keep_dims=keep_dims, name=name) File "C:\Users\jakub\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py",
line 509, in apply_op
(input_name, err)) ValueError: Tried to convert 'reduction_indices' to a tensor and failed. Error: Argument must be a
dense tensor: range(2, 3) - got shape 1, but wanted [].
Does anyone know why am I getting this error?
I am having the same problem. I changed the
self.diff_sum = tf.reduce_sum( self.diff_sq, reduction_indices=range(2,2+len(self.input_shape)) )
to
self.diff_sum = tf.reduce_sum( self.diff_sq,2 )
to just try to get it to run. This was the result after 400 iterations:
Kohonen_SOM_Colors_reduce_sum_bug