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 ...
随机推荐
- Win8操作系统下IIS如何配置asp.net的运行环境(win7同样)
一.把鼠标放在电脑屏幕的左下角然后右击,弹出如下图菜单,选择“程序和功能”(快捷键win+X).(win7点击电脑左下角的“开始”,然后点击“控制面板”打开程序与功能界面): 二.进入程序与功能界面后 ...
- c#如何判断两个对象是否相等
在c#中判断对象相等,这是对引用类型进行判断,而不是对值类型,如果是对字符串,或者是数值进行判断相等只需要用==运算符就可以了. 对两个对象用==运算符,只能判断他们两个在内存中的地址是否一样的. ...
- css对ie的兼容性问题处理(一):
1.在制作sidebar时对li里面的元素进行浮动,li在ie6/7下会出现4px的间间隙: 解决方法:在li下加上vertical-align属性,值可为top.bottom.middle: 扩展: ...
- ORA-00054 资源正忙
现象: 执行update.truncate提示 ORA-00054: resource busy and acquire with NOWAIT specified. 解决方法: 因为系统是RAC系统 ...
- opencv3.2.0图像离散傅里叶变换
源码: ##名称:离散傅里叶变换 ##平台:QT5.7.1+opencv3.2.0 ##日期:2017年12月13. /**** 新建QT控制台程序****/ #include <QCoreAp ...
- Android网络请求库RetrofitUtils
RetrofitUtils GitHub地址,帮忙给个Star 项目介绍 Retrofit+Okhttp辅助类的简单封装,vesion 1.0.X 实现了Get,Post-Form.Post-Json ...
- 如何在C/S下打印报表
java应用有不少是C/S模式,在C/S模式下,同样可以调用API接口运算报表.CSReport是C/S模式下的报表控件类,在这个类中可以获得报表的显示面板.获得报表的打印面板.显示报表打印窗口 ...
- Ubuntu 安装python
1. wget http://mirrors.sohu.com/python/3.6.0/Python-3.6.0.tar.xz wget https://www.python.org/ftp/pyt ...
- 产品经理都知道MVP,但是它可能不再是产品研发最好的模型了
产品经理都知道MVP,但是它可能不再是产品研发最好的模型了 孟小白Aspire • 2017-09-01 • 汽车交通 要简单.讨喜.完整,不要最小可行性产品.这对创业公司的第一个产品来说很重要. M ...
- 转: Dubbo远程调用服务框架原理与示例
Dubbo 是阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和 Spring 框架无缝集成. 主要核心部件: Remoting: 网络通 ...