■ 망델브로 집합을 출력하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import matplotlib.pyplot as pp import numpy as np import tensorflow as tf yNDArray, xNDArray = np.mgrid[-1.3:1.3:0.005, -2:1:0.005] zNDArray = xNDArray + 1j * yNDArray cTensor = tf.constant(zNDArray.astype(np.complex64)) zsVariable = tf.Variable(cTensor) nsVariable = tf.Variable(tf.zeros_like(cTensor, tf.float32)) session = tf.InteractiveSession() tf.global_variables_initializer().run() zsTensor = zsVariable * zsVariable + cTensor notDivergedTensor = tf.abs(zsTensor) < 4 stepOperation = tf.group(zsVariable.assign(zsTensor), nsVariable.assign_add(tf.cast(notDivergedTensor, tf.float32))) for i in range(200): stepOperation.run() pp.imshow(nsVariable.eval()) pp.show() |