23、TensorFlow教程--- 创建图表

偏微分方程(PDE)是一种涉及未知函数的偏导数以及多个独立变量的微分方程。关于偏微分方程,我们将重点关注创建新图形。

假设有一个尺寸为 500*500 的池塘 −

N = 500

现在,我们将计算偏微分方程并使用它来形成相应的图形。考虑以下步骤来计算图形。

步骤 1 − 导入用于模拟的库。

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt


 

步骤 2 − 包括用于将 2D 数组转换为卷积核和简化的 2D 卷积操作的函数。

def make_kernel(a):
   a = np.asarray(a)
   a = a.reshape(list(a.shape) + [1,1])
   return tf.constant(a, dtype=1)

def simple_conv(x, k):
   """一个简化的2D卷积操作"""
   x = tf.expand_dims(tf.expand_dims(x, 0), -1)
   y = tf.nn.depthwise_conv2d(x, k, [1, 1, 1, 1], padding = 'SAME')
   return y[0, :, :, 0]

def laplace(x):
   """计算数组的二维拉普拉斯"""
   laplace_k = make_kernel([[0.5, 1.0, 0.5], [1.0, -6., 1.0], [0.5, 1.0, 0.5]])
   return simple_conv(x, laplace_k)
   
se

猜你喜欢

转载自blog.csdn.net/Knowledgebase/article/details/133460037
今日推荐