TypeError: string argument expected, got 'bytes'
2017-08-25 13:34
579 查看
代码:
报错:
ModuleNotFoundError: No module named 'cStringIO'
AttributeError: module 'tensorflow' has no attribute 'complex_abs'
TypeError: string argument expected, got 'bytes'
解决办法:
from io import BytesIO
f = BytesIO()
not_diverged = tf.abs(zs_) < 4
# 导入仿真库 import tensorflow as tf import numpy as np # 导入可视化库 import PIL.Image from cStringIO import StringIO from IPython.display import clear_output, Image, display import scipy.ndimage as nd
# 导入仿真库 import tensorflow as tf import numpy as np # 导入可视化库 import PIL.Image from cStringIO import StringIO from IPython.display import clear_output, Image, display import scipy.ndimage as nd
def DisplayFractal(a, fmt='jpeg'): """显示迭代计算出的彩色分形图像。""" a_cyclic = (6.28*a/20.0).reshape(list(a.shape)+[1]) img = np.concatenate([10+20*np.cos(a_cyclic), 30+50*np.sin(a_cyclic), 155-80*np.cos(a_cyclic)], 2) img[a==a.max()] = 0 a = img a = np.uint8(np.clip(a, 0, 255)) f = StringIO() PIL.Image.fromarray(a).save(f, fmt) display(Image(data=f.getvalue()))
sess = tf.InteractiveSession()
# 使用NumPy创建一个在[-2,2]x[-2,2]范围内的2维复数数组 Y, X = np.mgrid[-1.3:1.3:0.005, -2:1:0.005] Z = X+1j*Y
xs = tf.constant(Z.astype("complex64")) zs = tf.Variable(xs) ns = tf.Variable(tf.zeros_like(xs, "float32"))
tf.initialize_all_variables().run()
# 计算一个新值z: z^2 + x zs_ = zs*zs + xs # 这个新值会发散吗? not_diverged = tf.complex_abs(zs_) < 4 # 更新zs并且迭代计算。 # # 说明:在这些值发散之后,我们仍然在计算zs,这个计算消耗特别大! # 如果稍微简单点,这里有更好的方法来处理。 # step = tf.group( zs.assign(zs_), ns.assign_add(tf.cast(not_diverged, "float32")) )
for i in range(200): step.run()
DisplayFractal(ns.eval())
def DisplayFractal(a, fmt='jpeg'): """显示迭代计算出的彩色分形图像。""" a_cyclic = (6.28*a/20.0).reshape(list(a.shape)+[1]) img = np.concatenate([10+20*np.cos(a_cyclic), 30+50*np.sin(a_cyclic), 155-80*np.cos(a_cyclic)], 2) img[a==a.max()] = 0 a = img a = np.uint8(np.clip(a, 0, 255)) f = StringIO() PIL.Image.fromarray(a).save(f, fmt) display(Image(data=f.getvalue()))
sess = tf.InteractiveSession()
# 使用NumPy创建一个在[-2,2]x[-2,2]范围内的2维复数数组 Y, X = np.mgrid[-1.3:1.3:0.005, -2:1:0.005] Z = X+1j*Y
xs = tf.constant(Z.astype("complex64")) zs = tf.Variable(xs) ns = tf.Variable(tf.zeros_like(xs, "float32"))
tf.initialize_all_variables().run()
# 计算一个新值z: z^2 + x zs_ = zs*zs + xs # 这个新值会发散吗? not_diverged = tf.complex_abs(zs_) < 4 # 更新zs并且迭代计算。 # # 说明:在这些值发散之后,我们仍然在计算zs,这个计算消耗特别大! # 如果稍微简单点,这里有更好的方法来处理。 # step = tf.group( zs.assign(zs_), ns.assign_add(tf.cast(not_diverged, "float32")) )
for i in range(200): step.run()
DisplayFractal(ns.eval())
报错:
ModuleNotFoundError: No module named 'cStringIO'
AttributeError: module 'tensorflow' has no attribute 'complex_abs'
TypeError: string argument expected, got 'bytes'
解决办法:
from io import BytesIO
f = BytesIO()
not_diverged = tf.abs(zs_) < 4
相关文章推荐
- TypeError: string argument expected, got 'bytes'
- python3 pycurl 出现 TypeError: string argument expected, got 'bytes' 解决方案
- Python出现TypeError: file() argument 1 must be encoded string without NULL bytes, not str问题解决
- TypeError: expected string or bytes-like object
- 【tensorFlow】tf.reshape()报错信息 - TypeError: Expected binary or unicode string, got -1
- python 点滴记录4:TypeError: range() integer end argument expected, got str.
- TypeError: __init__() got an unexpected keyword argument ‘maxlength’
- pip错误:TypeError: parse() got an unexpected keyword argument 'transport_encoding'
- pip错误:TypeError: parse() got an unexpected keyword argument 'transport_encoding'
- [已解决]Error:Error: Expected resource of type string [ResourceType]
- python3-网络编程-TypeError: send() argument 1 must be bytes or buffer, not str异常
- pip错误:TypeError: parse() got an unexpected keyword argument 'transport_encoding'
- python pandas 报错:TypeError: parser_f() got an unexpected keyword argument 'skip_blank_lines'
- TypeError: Expected int32, got list containing Tensors of type '_Message' instead.
- TypeError: unbound method func1() must be called with base1 instance as first argument (got nothing
- _compile(pattern, flags).findall(string) TypeError: cannot use a string pattern on a bytes-like
- pip错误:TypeError: parse() got an unexpected keyword argument 'transport_encoding'
- TypeError: __init__() got an unexpected keyword argument ‘default’
- RESTful学习笔记 --- TypeError: __init__() got an unexpected keyword argument 'method'
- Python 读写文件 错误TypeError: write() argument must be str, not bytes+