import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np import sklearn import pandas as pd import os import sys import time import timeit import tensorflow as tf from tensorflow import keras print(tf.__version__) print(sys.version_info) for module in mpl, np, pd, sklearn, tf, keras: print(module.__name__, module.__version__) ######################################################################################### # tf.function使python语法定义的函数转为TensorFlow中图的函数 # 图可以使运算结果更快 def scaled_elu(z,scale=1.0,alpha=1.0): # z >= 0 ? scale * z : scale * alpha * tf.nn.elu(z) # 这里使用了TensorFlow内置的函数,没有使用python中的函数,因为tf内置函数会对矩阵中每个值进行运算 is_positive = tf.greater_equal(z,0.0) value = scale * tf.where(is_positive, z, alpha * tf.nn.elu(z)) return value print(scaled_elu(tf