python matplotlib quiver——画箭头、风场
理解参考:https://blog.csdn.net/liuchengzimozigreat/article/details/84566650
以下实例

import numpy as np
import matplotlib.pyplot as plt def function(x):
return np.sum(x**2)#return x[0]**2 + x[1]**2 def _numerical_gradient_no_batch(f,x):
h = 1e-4
grad = np.zeros_like(x)
for idx in range(x.size):
tmp_va1 = x[idx]
x[idx] = float(tmp_va1) + h
fxh1 =f(x) x[idx] = tmp_va1 -h
fxh2 = f(x)
grad[idx] = (fxh1- fxh2)/(2*h) x[idx] = tmp_va1
print("grad:"+str(grad))
return grad def numerical_gradient(f,X):
if X.ndim == 1:
return _numerical_gradient_no_batch(f,X)
else:
grad = np.zeros_like(X)
for idx,x in enumerate(X):
grad[idx] = _numerical_gradient_no_batch(f,x)
return grad def function_2(x):
if x.ndim == 1:
return np.sum(x **2)
else:
return np.sum(x**2,axis=1) def tangent_line(f,x):
d = numerical_gradient(f,x)
print(d)
y = f(x) - d * x
return lambda t : d * t + y print(_numerical_gradient_no_batch(function_2,np.array([3.0,4.0])))
print(numerical_gradient(function_2,np.array([3.0,4.0])))
print(numerical_gradient(function_2,np.array([[3.0,4.0],[0.0,2.0],[3.0,0.0]])))
if __name__ =='__main__':
x0= np.arange(-2,2.5,0.25)
x1=np.arange(-2,2.5,0.25)
X,Y= np.meshgrid(x0,x1)
X = X.flatten()
Y = Y.flatten() grad = numerical_gradient(function_2,np.array([X,Y])) plt.figure()
plt.quiver(X,Y,-grad[0],-grad[1],angles="xy",color="#666666")
plt.xlim([-2,2])
plt.ylim([-2,2])
plt.xlabel('x0')
plt.ylabel('x1')
plt.grid()
plt.legend()
plt.draw()
plt.show()
python matplotlib quiver——画箭头、风场的更多相关文章
- Python matplotlib pylab 画张图
from pylab import * w1 = 1 w2 = 25 fs = 18 y = np.arange(-2,2,0.001) x = w1*y*log(y)-1.0/w2*exp(-(w2 ...
- Python - matplotlib 数据可视化
在许多实际问题中,经常要对给出的数据进行可视化,便于观察. 今天专门针对Python中的数据可视化模块--matplotlib这块内容系统的整理,方便查找使用. 本文来自于对<利用python进 ...
- 转:使用 python Matplotlib 库 绘图 及 相关问题
使用 python Matplotlib 库绘图 转:http://blog.csdn.net/daniel_ustc/article/details/9714163 Matplotlib ...
- 安装python Matplotlib 库
转:使用 python Matplotlib 库 绘图 及 相关问题 使用 python Matplotlib 库绘图 转:http://blog.csdn.net/daniel_ustc ...
- 在matlab 画箭头
[转载]在matlab 画箭头 原文地址:在matlab 画箭头作者:纯情小郎君 完整见链接http://www.mathworks.com/matlabcentral/fx_files/14056/ ...
- python matplotlib 中文显示参数设置
python matplotlib 中文显示参数设置 方法一:每次编写代码时进行参数设置 #coding:utf-8import matplotlib.pyplot as pltplt.rcParam ...
- python matplotlib plot 数据中的中文无法正常显示的解决办法
转发自:http://blog.csdn.net/laoyaotask/article/details/22117745?utm_source=tuicool python matplotlib pl ...
- python matplotlib画图产生的Type 3 fonts字体没有嵌入问题
ScholarOne's 对python matplotlib画图产生的Type 3 fonts字体不兼容,更改措施: 在程序中添加如下语句 import matplotlib matplotlib. ...
- 菱形实现气泡Bubble,菱形画箭头,菱形画三角形
菱形实现气泡Bubble,菱形画箭头,菱形画三角形 >>>>>>>>>>>>>>>>>>&g ...
随机推荐
- WCF服务使用(IIS+Http)和(Winform宿主+Tcp)两种方式进行发布
1.写在前面 刚接触WCF不久,有很多地方知其然不知其所以然.当我在[创建服务->发布服务->使用服务]这一过程出现过许多问题.如客户端找不到服务引用:客户端只在本机环境中才能访问服务,移 ...
- leaflet 整合 esri
此 demo 通过 proj4js 将 leaflet 与 esri 整合起来,同时添加了 ClusteredFeatureLayer 的支持. 下载 <html> <head> ...
- 网络I/O模型--01阻塞模式(普通)
很长一段时间内,大多数网络通信方式都是阻塞模式,即: · 客户端 向服务器端发出请求后,客户端会一直处于等待状态(不会再做其他事情),直到服务器端返回结果或者网络出现问题 . · 服务器端同样如此,当 ...
- 润乾填报页面导入excel后增加js动作
当页面从excel中导入数据之后,自动加入js的检查功能,下面是如何在导入excel后直接引入js的功能实例: var _orgImportExcel = report1_importExcel ...
- java 内存分析之方法返回值及匿名对象一
package Demo; public class Point { private double x, y, z; public Point(double _x, double _y, double ...
- java实现Kafka的消费者示例
使用java实现Kafka的消费者 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 3 ...
- 将 ExpressRoute 线路从经典部署模型转移到 Resource Manager 部署模型
本文概述将 Azure ExpressRoute 线路从经典部署模型转移到 Azure Resource Manager 部署模型的效果. Azure 当前使用两种部署模型:Resource Mana ...
- MVC 在视图中获取当前的Controller、Action的方式
在视图中获取Controller和Action的方式: Controller: @ViewContext.RouteData.Route.GetRouteData(this.Context).Valu ...
- Linq排序方式与Lambda排序方式比较以及OrderBy、ThenBy的使用
沿用之前某一篇文章的实体类与EF操作类代码.数据库中增加几条数据 Linq 的排序方式,下面例子是根据RoleId 升序,Name降序 EFContext<Member> efMember ...
- java并发之同步辅助类CyclicBarrier和CountDownLatch
CyclicBarrier 的字面意思是可循环使用(Cyclic)的屏障(Barrier).它要做的事情是,让一组线程到达一个屏障(也可以叫同步点)时被阻塞,直到最后一个线程到达屏障时,屏障才会开门, ...