- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
'''导入模拟库'''
import tensorflow as tf
import numpy as np
'''为可视化导入'''
from PIL.Image
from io import BytesIO
from IPython.display import Image, display
'''现在我们将定义一个函数来实际显示图像 迭代次数'''
def DisplayFractal(a, fmt='jpeg'):
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 = BytesIO()
PIL.Image.fromarray(a).save(f, fmt)
display(Image(data=f.getvalue()))
sess = tf.InteractiveSession()
# Use NumPy to create a 2D array of complex numbers
Y, X = np.mgrid[-1.3:1.3:0.005, -2:1:0.005]
Z = X+1j*Y
print(Z)
#Now we define and initialize TensorFlow tensors.
xs = tf.constant(Z.astype(np.complex64))
zs = tf.Variable(xs)
ns = tf.Variable(tf.zeros_like(xs, tf.float32))
tf.global_variables_initializer().run()
zs_ = zs*zs + xs
print(zs)
# Have we diverged with this new value?
not_diverged = tf.abs(zs_) < 4
'''更新 zs 和迭代计数的操作。注意:我们在它们发散后继续计算 zs!这很浪费!有更好的,如果有一点不太简单,方法来做到这一点。''' step = tf.group(zs.assign(zs_), ns.assign_add(tf.cast(not_diverged, tf.float32)))
for i in range(200): step.run()
DisplayFractal(ns.eval())
最佳答案
我遇到了同样的问题。您必须在 Jupyter notebook 中运行 TensorFlow 示例: http://jupyter.org/
如果您从其他 IDE(例如(Spyder))运行它,您将看到的是 <IPython.core.display.Image object>
在控制台中。
关于python - 如何在 Mandlebrot tensorflow 程序中显示图像。当前输出是 <IPython.core.display.Image object>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43227758/
我是 python 的新手,我对它生成分形图像的能力非常感兴趣。我自己写了一些简单的,但我刚刚发现了一个 Mandelbrot 分形的脚本......它以你想要的分辨率生成美丽的全彩色图像......
为了尝试学习 OpenCL,我决定绘制 Mandlebrot 集的图。它似乎在 CPU 上运行良好。下面的两张图片显示了在 CPU(Intel(R) Core(TM) i5-3210M CPU @ 2
'''导入模拟库''' import tensorflow as tf import numpy as np '''为可视化导入''' from PIL.Image from io import By
我是一名优秀的程序员,十分优秀!