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 ...
随机推荐
- before(),after(),prepend(),append()等新DOM方法简介
一.DOM API也在不断升级 web前端标准一直在不断升级,比方说,说了很多年的HTML5.CSS3,以及天天见的ES6. 然后,似乎就没有然后了.实际上,除了HTML5/CSS3/ES6+,关于D ...
- 一文总结学习 Python 的 14 张思维导图
本文主要涵盖了 Python 编程的核心知识(暂不包括标准库及第三方库,后续会发布相应专题的文章). 首先,按顺序依次展示了以下内容的一系列思维导图:基础知识,数据类型(数字,字符串,列表,元组,字典 ...
- Spring 、SpringMVC 、Struts2之间的区别
一.Spring与SpringMVC的区别: spring是一个开源框架,是为了解决企业应用程序开发,功能如下: 功能:使用基本的JavaBean代替EJB,并提供了更多的企业应用功能 范围:任何Ja ...
- 使用display:none和visibility:hidden隐藏的区别
今天做毕设时遇到了一个小问题,我做了一个tab导航栏,点击一个tab页其它tab页隐藏,这时候第一想法是使用display:none来控制显示隐藏,写了之后发现使用display会有一个问题,就是第二 ...
- 移动端点击输入框,弹出键盘,底部被顶起问题(vue)
这个问题相信做移动端开发的童鞋会有深刻体会,以前用jq开发时就很头疼这个问题,每次底部footer部分需要用position:fixed,如果页面内容不是很长,没有超出屏幕范围,那就还好,没有问题:一 ...
- Dynamics 365Online 查询Web Api的请求WebUri
在on-premises版本中,获取weburi的方式是进设置-自定义项-开发人员资源中查看地址,但online版本中的地址会有些许的差异 online的开发者资源中的地址如下图,如果你在页面java ...
- 怎么配置eclipse的联想功能
第一步:打开Eclipse,windows下,打开“window”→“Preferences” :mac下,打开“偏好设置”. 第二步:选择“Java”,展开,“Editor”,选择“Content ...
- C# SqlConnection连接sql server
try { SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Data Source=127.0.0.1; ...
- Pwn Heap With Tcache
Pwn Heap With Tcache 前言 glibc 2.26 开始引入了 tcache , 相关的 commit 可以看 这里 .加入 tcache 对性能有比较大的提升,不过由于 tcach ...
- Selectivizr-让IE6~8支持CSS3伪类和属性选择器
一.下载和demo 下载: 您可以狠狠地点击这里:selectivizr-1.0.0.zip(右键-[目标|链接另存为] 9.24K) demo: 您可以狠狠地点击这里:Selectivizr部分属性 ...