res_DE=differential_evolution(invSortino,bounds=bounds, disp=True)
where invSortino takes an iterable of length x ad returns a negative scalar.
bounds are defined by
lb=[1e-03]*data.shape[1]
ub=[.4]*data.shape[1]
bounds=Bounds(lb,ub)
Or
#bounds=[(0,.4)]*data.shape[1]
the length of bounds is correct,(method 2 above)
but iterable generated has a length 0
print('shapes: ',weights.shape,data.shape)
results in
shapes: (0,) (951, 65)
which results in the error
Traceback (most recent call last):
File "C:\Users\anaconda3\lib\site-packages\scipy\optimize\_differentialevolution.py", line 878, in _calculate_population_energies
parameters_pop[0:nfevs]))
File "C:\Users\anaconda3\lib\site-packages\scipy\optimize\_differentialevolution.py", line 1265, in __call__
return self.f(x, *self.args)
File "c:/Users/try.py", line 68, in invSortino
rets=data*weights
File "C:\Users\anaconda3\lib\site-packages\pandas\core\ops\__init__.py", line 695, in f
other = _align_method_FRAME(self, other, axis)
File "C:\Users\anaconda3\lib\site-packages\pandas\core\ops\__init__.py", line 644, in _align_method_FRAME
right = to_series(right)
File "C:\Users\anaconda3\lib\site-packages\pandas\core\ops\__init__.py", line 636, in to_series
msg.format(req_len=len(left.columns), given_len=len(right))
ValueError: Unable to coerce to Series, **length must be 65: given 0**
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
line 85, in <module>
res_DE=differential_evolution(invSortino,bounds=bounds, disp=True)
File "C:\Users\anaconda3\lib\site-packages\scipy\optimize\_differentialevolution.py", line 306, in differential_evolution
ret = solver.solve()
File "C:\Users\anaconda3\lib\site-packages\scipy\optimize\_differentialevolution.py", line 745, in solve
self.population[self.feasible]))
File "C:\Users\anaconda3\lib\site-packages\scipy\optimize\_differentialevolution.py", line 883, in _calculate_population_energies
raise RuntimeError("The map-like callable must be of the"
RuntimeError: The map-like callable must be of the form f(func, iterable), returning a sequence of numbers the same length as 'iterable'
Related
I want to save the data set as a parquet file, called power.parquet, and I use df.to_parquet(<filename>). But it gives me this errer "ValueError: Error converting column "Global_reactive_power" to bytes using encoding UTF8. Original error: bad argument type for built-in operation" And I installed the fastparquet package.
from fastparquet import write, ParquetFile
dat.to_parquet("power.parquet")
df_parquet = ParquetFile("power.parquet").to_pandas()
df_parquet.head() # Test your final value
`*Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.9/site-packages/fastparquet/writer.py", line 259, in convert
out = array_encode_utf8(data)
File "fastparquet/speedups.pyx", line 50, in fastparquet.speedups.array_encode_utf8
TypeError: bad argument type for built-in operation
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/folders/4f/bm2th1p56tz4rq_zffc8g3940000gn/T/ipykernel_85477/3080656655.py", line 1, in <module>
dat.to_parquet("power.parquet", compression="GZIP")
File "/opt/anaconda3/lib/python3.9/site-packages/dask/dataframe/core.py", line 4560, in to_parquet
return to_parquet(self, path, *args, **kwargs)
File "/opt/anaconda3/lib/python3.9/site-packages/dask/dataframe/io/parquet/core.py", line 732, in to_parquet
return compute_as_if_collection(
File "/opt/anaconda3/lib/python3.9/site-packages/dask/base.py", line 315, in compute_as_if_collection
return schedule(dsk2, keys, **kwargs)
File "/opt/anaconda3/lib/python3.9/site-packages/dask/threaded.py", line 79, in get
results = get_async(
File "/opt/anaconda3/lib/python3.9/site-packages/dask/local.py", line 507, in get_async
raise_exception(exc, tb)
File "/opt/anaconda3/lib/python3.9/site-packages/dask/local.py", line 315, in reraise
raise exc
File "/opt/anaconda3/lib/python3.9/site-packages/dask/local.py", line 220, in execute_task
result = _execute_task(task, data)
File "/opt/anaconda3/lib/python3.9/site-packages/dask/core.py", line 119, in _execute_task
return func(*(_execute_task(a, cache) for a in args))
File "/opt/anaconda3/lib/python3.9/site-packages/dask/utils.py", line 35, in apply
return func(*args, **kwargs)
File "/opt/anaconda3/lib/python3.9/site-packages/dask/dataframe/io/parquet/fastparquet.py", line 1167, in write_partition
rg = make_part_file(
File "/opt/anaconda3/lib/python3.9/site-packages/fastparquet/writer.py", line 716, in make_part_file
rg = make_row_group(f, data, schema, compression=compression,
File "/opt/anaconda3/lib/python3.9/site-packages/fastparquet/writer.py", line 701, in make_row_group
chunk = write_column(f, coldata, column,
File "/opt/anaconda3/lib/python3.9/site-packages/fastparquet/writer.py", line 554, in write_column
repetition_data, definition_data, encode[encoding](data, selement), 8 * b'\x00'
File "/opt/anaconda3/lib/python3.9/site-packages/fastparquet/writer.py", line 354, in encode_plain
out = convert(data, se)
File "/opt/anaconda3/lib/python3.9/site-packages/fastparquet/writer.py", line 284, in convert
raise ValueError('Error converting column "%s" to bytes using '
ValueError: Error converting column "Global_reactive_power" to bytes using encoding UTF8. Original error: bad argument type for built-in operation
*
I tried by adding object_coding = "bytes".I want to solve this problem.
I'm using python image_match library. I need to use search_image method of this library. but when I se this method I got the below error:
Traceback (most recent call last):
File "/var/www/html/Panel/test2.py", line 16, in <module>
ses.search_image('https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg/687px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg')
File "/usr/local/lib/python3.10/site-packages/image_match/signature_database_base.py", line 268, in search_image
transformed_record = make_record(img, self.gis, self.k, self.N)
File "/usr/local/lib/python3.10/site-packages/image_match/signature_database_base.py", line 356, in make_record
signature = gis.generate_signature(path)
File "/usr/local/lib/python3.10/site-packages/image_match/goldberg.py", line 161, in generate_signature
im_array = self.preprocess_image(path_or_image, handle_mpo=self.handle_mpo, bytestream=bytestream)
File "/usr/local/lib/python3.10/site-packages/image_match/goldberg.py", line 257, in preprocess_image
return rgb2gray(image_or_path)
File "/usr/local/lib/python3.10/site-packages/skimage/_shared/utils.py", line 394, in fixed_func
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/skimage/color/colorconv.py", line 875, in rgb2gray
rgb = _prepare_colorarray(rgb)
File "/usr/local/lib/python3.10/site-packages/skimage/color/colorconv.py", line 140, in _prepare_colorarray
raise ValueError(msg)
ValueError: the input array must have size 3 along `channel_axis`, got (1024, 687)
Can you please help me?
I am trying to visualize a correlation matrix for categorical variables which are first Hot-Encoded. After that, the code throws me still an error and I am not sure why.
X= pandas.DataFrame(A, B, C, D, E)
le = preprocessing.LabelEncoder()
X= X.apply(le.fit_transform)
plt.figure(figsize=(15,10))
sns.heatmap(X.corr(),vmin=-1,cmap='YlGnBu',annot=True);
plt.title("Correlation Matrix", fontsize=24)
plt.show()
TypeError('argument must be a string or number')
What am I doing wrong? Here is the full error. Please note I am using the Python script editor within Power BI to visualize.
Error Message:
Python script error.
Traceback (most recent call last):
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\preprocessing\label.py", line 105, in _encode
res = _encode_python(values, uniques, encode)
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\preprocessing\label.py", line 59, in _encode_python
uniques = sorted(set(values))
TypeError: '<' not supported between instances of 'str' and 'float'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "PythonScriptWrapper.PY", line 30, in <module>
dataset = dataset.apply(le.fit_transform)
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\frame.py", line 6487, in apply
return op.get_result()
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\apply.py", line 151, in get_result
return self.apply_standard()
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\apply.py", line 257, in apply_standard
self.apply_series_generator()
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\apply.py", line 286, in apply_series_generator
results[i] = self.f(v)
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\preprocessing\label.py", line 236, in fit_transform
self.classes_, y = _encode(y, encode=True)
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\preprocessing\label.py", line 107, in _encode
raise TypeError("argument must be a string or number")
TypeError: ('argument must be a string or number', 'occurred at index connection')
Stack Trace:
Microsoft.PowerBI.ExploreServiceCommon.ScriptHandlerException: Python script error.
Traceback (most recent call last):
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\preprocessing\label.py", line 105, in _encode
res = _encode_python(values, uniques, encode)
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\preprocessing\label.py", line 59, in _encode_python
uniques = sorted(set(values))
TypeError: '<' not supported between instances of 'str' and 'float'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "PythonScriptWrapper.PY", line 30, in <module>
dataset = dataset.apply(le.fit_transform)
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\frame.py", line 6487, in apply
return op.get_result()
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\apply.py", line 151, in get_result
return self.apply_standard()
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\apply.py", line 257, in apply_standard
self.apply_series_generator()
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\apply.py", line 286, in apply_series_generator
results[i] = self.f(v)
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\preprocessing\label.py", line 236, in fit_transform
self.classes_, y = _encode(y, encode=True)
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\preprocessing\label.py", line 107, in _encode
raise TypeError("argument must be a string or number")
TypeError: ('argument must be a string or number', 'occurred at index connection')
---> Microsoft.PowerBI.Scripting.Python.Exceptions.PythonScriptRuntimeException: Python script error.
Traceback (most recent call last):
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\preprocessing\label.py", line 105, in _encode
res = _encode_python(values, uniques, encode)
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\preprocessing\label.py", line 59, in _encode_python
uniques = sorted(set(values))
TypeError: '<' not supported between instances of 'str' and 'float'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "PythonScriptWrapper.PY", line 30, in <module>
dataset = dataset.apply(le.fit_transform)
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\frame.py", line 6487, in apply
return op.get_result()
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\apply.py", line 151, in get_result
return self.apply_standard()
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\apply.py", line 257, in apply_standard
self.apply_series_generator()
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\apply.py", line 286, in apply_series_generator
results[i] = self.f(v)
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\preprocessing\label.py", line 236, in fit_transform
self.classes_, y = _encode(y, encode=True)
File "C:\Users\abc\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\preprocessing\label.py", line 107, in _encode
raise TypeError("argument must be a string or number")
TypeError: ('argument must be a string or number', 'occurred at index connection')
at Microsoft.PowerBI.Scripting.Python.PythonScriptWrapper.RunScript(String originalScript, Int32 timeoutMs)
at Microsoft.PowerBI.Client.Windows.Python.PythonScriptHandler.GenerateVisual(ScriptHandlerOptions options)
--- End of inner exception stack trace ---
at Microsoft.PowerBI.Client.Windows.Python.PythonScriptHandler.GenerateVisual(ScriptHandlerOptions options)
at Microsoft.PowerBI.ExploreServiceCommon.ScriptVisualCommandFlow.RunInternal(Stream dataShapeResultStream, QueryBindingDescriptor& bindingDescriptor)
at Microsoft.PowerBI.ExploreServiceCommon.ScriptVisualCommandFlow.Run(Stream dataShapeResultStream, QueryBindingDescriptor& bindingDescriptor)
at Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.TransformDataShapeResult(QueryCommand transformCommand, SemanticQueryDataShapeCommand command, Stream dataShapeResultStream, QueryBindingDescriptor& bindingDescriptor)
at Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.ExecuteDataQuery(IQueryResultDataWriter queryResultDataWriter, EngineDataModel engineDataModel, DataQuery query, Int32 queryId, ServiceErrorStatusCode& serviceErrorStatusCode, CancellationToken cancelToken)
at Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.ProcessAndWriteSemanticQueryCommands(IQueryResultsWriter queryResultsWriter, IList`1 queries, HashSet`1 pendingQueriesToCancel, EngineDataModel engineDataModel)
Invocation Stack Trace:
at Microsoft.Mashup.Host.Document.ExceptionExtensions.GetCurrentInvocationStackTrace()
at Microsoft.Mashup.Client.UI.Shared.StackTraceInfo..ctor(String exceptionStackTrace, String invocationStackTrace, String exceptionMessage)
at Microsoft.PowerBI.Client.Windows.ErrorHostService.GetErrorDetails(ShowErrorDialogArgs args)
at Microsoft.PowerBI.Client.Windows.ErrorHostService.<>c__DisplayClass2_0.<<ShowErrorDialog>b__0>d.MoveNext()
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)
at Microsoft.PowerBI.Client.Windows.ErrorHostService.<>c__DisplayClass2_0.<ShowErrorDialog>b__0()
at Microsoft.Mashup.Host.Document.SynchronizationContextExtensions.<>c__DisplayClass1_0`1.<SendAndMarshalExceptions>b__0()
at Microsoft.Mashup.Host.Document.SynchronizationContextExtensions.<>c__DisplayClass0_1.<SendAndMarshalExceptions>b__0(Object null)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at Microsoft.Mashup.Client.UI.Shared.WebDialogs.WebDialog.<>n__0(IWindowHandle owner)
at Microsoft.Mashup.Client.UI.Shared.WindowManager.ShowModal[T](T dialog, Func`1 showModalFunction)
at Microsoft.PowerBI.Client.Program.<>c__DisplayClass4_0.<Main>b__1()
at Microsoft.PowerBI.Client.Windows.IExceptionHandlerExtensions.<>c__DisplayClass3_0.<HandleExceptionsWithNestedTasks>b__0()
at Microsoft.Mashup.Host.Document.ExceptionHandlerExtensions.HandleExceptions(IExceptionHandler exceptionHandler, Action action)
at Microsoft.PowerBI.Client.Program.Main(String[] args)
I figured it out. It was a Power BI setting in the variables that were selected in the main pane which were inconsistent with the ones in the code. It needs to be the same across.
I literally have these two lines of code in sequence:
print(len(counter.ondas))
onda = counter.ondas[-1]
I got 13 printed for the first line and it crashed giving me tracebook to the onda = counter.ondas[-1] line saying IndexError: list index out of range right after printing len(list).
It works thousands of times before crashing. I have no clue on how to approach this problem.
Output for print(counter.ondas):
[Onda([<workers.mov.Mov object at 0x244EA050>], [Candle(4, 'GBP_JPY', Timestamp('2017-06-12 16:59:00'), 138.884, 138.897, 138.674, 138.76, 10957.0, True)]), Onda([<workers.mov.Mov object at 0x245073D0>], [Candle(4, 'GBP_JPY', Timestamp('2017-06-12 16:59:00'), 138.884, 138.897, 138.674, 138.76, 10957.0, True)...]
Output for print(type(counter.ondas)):
<class 'list'>
Output for print(isinstance(counter.ondas, list)):
True
Full Error Traceback
Traceback (most recent call last):
File "C:\Users\joaoa\AppData\Local\Programs\Python\Python36-32\lib\multiprocessing\pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "C:\Users\joaoa\AppData\Local\Programs\Python\Python36-32\lib\multiprocessing\pool.py", line 44, in mapstar
return list(map(*args))
File "C:\Users\joaoa\PycharmProjects\aquitania\general_manager.py", line 88, in load_observer_manager
observer_manager.update_load_run_data()
File "C:\Users\joaoa\PycharmProjects\aquitania\observer\management\observer_manager.py", line 78, in update_load_run_data
self.load_run_data()
File "C:\Users\joaoa\PycharmProjects\aquitania\observer\management\observer_manager.py", line 91, in load_run_data
self.feeder.exec_df(df[self.start_date:])
File "C:\Users\joaoa\PycharmProjects\aquitania\data_source\feeder.py", line 429, in exec_df
self.feed(candle)
File "C:\Users\joaoa\PycharmProjects\aquitania\data_source\feeder.py", line 98, in feed
self.make_candle(ts, candle, criteria_table)
File "C:\Users\joaoa\PycharmProjects\aquitania\data_source\feeder.py", line 126, in make_candle
self.set_values(ts, candle)
File "C:\Users\joaoa\PycharmProjects\aquitania\data_source\feeder.py", line 310, in set_values
ts_obs.feed_complete(self._candles[ts])
File "C:\Users\joaoa\PycharmProjects\aquitania\observer\management\observer_loader.py", line 100, in feed_complete
observer.update_last_candle(candle, store_candle)
File "C:\Users\joaoa\PycharmProjects\aquitania\observer\abstract\observer_abc.py", line 93, in update_last_candle
self.set_observe(self.update_method(candle))
File "C:\Users\joaoa\PycharmProjects\aquitania\observer\ondas\ondas_inside.py", line 393, in update_method
self.update_routine(counter_id=2, candle=candle)
File "C:\Users\joaoa\PycharmProjects\aquitania\observer\ondas\ondas_inside.py", line 412, in update_routine
onda = list(counter.ondas)[-1]
IndexError: list index out of range
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:/Users/joaoa/PycharmProjects/aquitania/general_manager.py", line 145, in <module>
gm.run()
File "C:/Users/joaoa/PycharmProjects/aquitania/general_manager.py", line 113, in run
list_of_observer_managers = self.load_all_observer_managers()
File "C:/Users/joaoa/PycharmProjects/aquitania/general_manager.py", line 60, in load_all_observer_managers
observer = currency_pool.map(self.load_observer_manager, list_of_currencies)
File "C:\Users\joaoa\AppData\Local\Programs\Python\Python36-32\lib\multiprocessing\pool.py", line 266, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "C:\Users\joaoa\AppData\Local\Programs\Python\Python36-32\lib\multiprocessing\pool.py", line 644, in get
raise self._value
IndexError: list index out of range
I was able to idenfity the issue. The error was being thrown in a separate process than the one that was being printed and for some reason the error ocurred only after the process that was printing the results was interrupted by another unrelated error.
Weird behavior, but now I am able to tackle the problem.
Debugging in a single process mode helped a lot.
Thank you for your help.
This is the code which has some problem:
symbol_returns[i*num_samples + sample_iter] = tf.multiply(tf.cast(pos[i*num_samples + sample_iter], np.float32), y_[:,i])
daily_returns_by_symbol_ = tf.concat( [tf.reshape(t, [-1,1],1) for t in symbol_returns.values()])
But there is some error, and I have no idea how to solve it.
Traceback (most recent call last):
File "neural_net_exec.py", line 129, in <module>
daily_returns_by_symbol_ = tf.concat( [tf.reshape(t, [-1,1],1) for t in symbol_returns.values()])
File "neural_net_exec.py", line 129, in <listcomp>
daily_returns_by_symbol_ = tf.concat( [tf.reshape(t, [-1,1],1) for t in symbol_returns.values()])
File "/anaconda/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/ops/gen_array_ops.py", line 2619, in reshape
name=name)
File "/anaconda/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 374, in apply_op
with g.as_default(), ops.name_scope(name) as scope:
File "/anaconda/envs/tensorflow/lib/python3.5/contextlib.py", line 59, in __enter__
return next(self.gen)
File "/anaconda/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 4522, in name_scope
with g.as_default(), g.name_scope(n) as scope:
File "/anaconda/envs/tensorflow/lib/python3.5/contextlib.py", line 59, in __enter__
return next(self.gen)
File "/anaconda/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 3171, in name_scope
if not _VALID_OP_NAME_REGEX.match(name):
TypeError: expected string or bytes-like object
The third argument to tf.reshape, which is optional, should be a string; you have used an integer (i.e., 1) as the third argument to tf.reshape, hence the error message.