莫烦Pytorch神经网络第二章代码修改

import torch
import numpy as np"""
Numpy Torch对比课程
"""
# #tensor与numpy格式数据相互转换
# np_data = np.arange(6).reshape((2,3))
# print(np_data)
#
# torch_data = torch.from_numpy(np_data)
# print('\n',torch_data)
#
# tensor2array = torch_data.numpy()
# print('\n',tensor2array)# #abs绝对值
# data = [-1,-2,1,2]
# tensor = torch.FloatTensor(data)    #32bit
# print(abs(tensor))
# print('\n',np.abs(data))
# print('\n',torch.abs(tensor))# #矩阵相乘
# data = [[1,2],[3,4]]
# tensor = torch.FloatTensor(data) #32-bit
# print('\n',np.matmul(data,data))
# print('\n',torch.mm(tensor,tensor))
#
# #注意:numpy.dot实现的是叉乘,tensor.dot是点乘
# data = np.array(data)
# print('\n',data.dot(data))
# print('\n',tensor.dot(tensor))      #注意这里会报错 新版本的要求dot需要一维输入,而我们设定的tensor是二维,旧版本实现的是点乘"""
Variable变量课程
"""# #这节内容我学习了一下 但是无法运行,原因是新版本的torch的Variable函数将返回tensor数据,同时requires_grad将有默认值,无需填写。var.backward()函数可以直接支持使用tensor了。
# from torch.autograd import Variable
#
# tensor = torch.FloatTensor[[1,2],[3,4]]
# variable = Variable(tensor,requires_grad = True)
#
# t_out = torch.mean(tensor*tensor)
# v_out = torch.mean(variable*variable)
#
# v_out.backward()
# print(variable.grad)
# print(variable.data)        #tensor形势
# print(variable.data.numpy)"""
激励函数课程
"""
import torch.nn.functional as F
from torch.autograd import Variable
import matplotlib.pyplot as plt#fake data
x = torch.linspace(-5,5,200)
x = Variable(x)
x_np = x.data.numpy()   #画图时要转化为numpy格式y_relu = F.relu(x).data.numpy()
y_sigmoid = F.sigmoid(x).data.numpy()
y_tanh = F.tanh(x).data.numpy()
y_softplus = F.softplus(x).data.numpy()plt.subplot(221)
plt.plot(x_np,y_relu,c='red',label='relu')
plt.ylim((-1,5))
plt.legend(loc="best")plt.subplot(222)
plt.plot(x_np,y_sigmoid,c='red',label='sigmoid')
plt.ylim((-0.2,1.2))
plt.legend(loc="best")plt.subplot(223)
plt.plot(x_np,y_tanh,c='red',label='tanh')
plt.ylim((-1.2,1.2))
plt.legend(loc="best")plt.subplot(224)
plt.plot(x_np,y_softplus,c='red',label='softplus')
plt.ylim((-0.2,6))
plt.legend(loc="best")plt.show()

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/389448.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

自定义字符类

当 VC不使用MFC,无法使用属于MFC的CString,为此自定义一个,先暂时使用,后续完善。 头文件: #pragma once#define MAX_LOADSTRING 100 // 最大字符数class CString {public:char *c_str, cSAr[MAX_LOADSTRING];WCHAR *w…

使用python和javascript进行数据可视化

Any data science or data analytics project can be generally described with the following steps:通常可以通过以下步骤来描述任何数据科学或数据分析项目: Acquiring a business understanding & defining the goal of a project 获得业务理解并定义项目目…

Android 事件处理

事件就是用户对图形的操作,在android手机和平板电脑上,主要包含物理按键事件和触摸屏事件两类。物理按键事件包含:按下、抬起、长按等;触摸屏事件主要包含按下、抬起、滚动、双击等。 在View中提供了onTouchEvent()方法&#xff0…

莫烦Pytorch神经网络第三章代码修改

3.1Regression回归 import torch import torch.nn.functional as F from torch.autograd import Variable import matplotlib.pyplot as plt""" 创建数据 """x torch.unsqueeze(torch.linspace(-1,1,100),dim1) y x.pow(2) 0.2*torch.rand(x…

为什么饼图有问题

介绍 (Introduction) It seems as if people are split on pie charts: either you passionately hate them, or you are indifferent. In this article, I am going to explain why pie charts are problematic and, if you fall into the latter category, what you can do w…

New Distinct Substrings(后缀数组)

New Distinct Substrings&#xff08;后缀数组&#xff09; 给定一个字符串&#xff0c;求不相同的子串的个数。\(n<50005\)。 显然&#xff0c;任何一个子串一定是后缀上的前缀。先&#xff08;按套路&#xff09;把后缀排好序&#xff0c;对于当前的后缀\(S_i\)&#xff0…

Android dependency 'com.android.support:support-v4' has different version for the compile (26.1.0...

在项目中加入react-native-camera的时候 出现的错误. 解决方案: 修改 implementation project(:react-native-camera)为 implementation (project(:react-native-camera)) {exclude group: "com.android.support"}查看原文 Could not find play-services-basement.aa…

先知模型 facebook_使用Facebook先知进行犯罪率预测

先知模型 facebookTime series prediction is one of the must-know techniques for any data scientist. Questions like predicting the weather, product sales, customer visit in the shopping center, or amount of inventory to maintain, etc - all about time series …

莫烦Pytorch神经网络第四章代码修改

4.1CNN卷积神经网络 import torch import torch.nn as nn from torch.autograd import Variable import torch.utils.data as Data import torchvision import matplotlib.pyplot as pltEPOCH 1 BATCH_SIZE 50 LR 0.001 DOWNLOAD_MNIST False #如果数据集已经下载到…

github gists 101使代码共享漂亮

If you’ve been going through Medium, looking at technical articles, you’ve undoubtedly seen little windows that look like the below:如果您一直在阅读Medium&#xff0c;并查看技术文章&#xff0c;那么您无疑会看到类似于以下内容的小窗口&#xff1a; def hello_…

loj #6278. 数列分块入门 2

题目 题解 区间修改&#xff0c;询问区间小于c的个数。分块排序&#xff0c;用vector。至于那个块的大小&#xff0c;好像要用到均值不等式 我不太会。。。就开始一个个试&#xff0c;发现sizsqrt(n)/4时最快&#xff01;&#xff01;&#xff01;明天去学一下算分块复杂度的方…

基于Netty的百万级推送服务设计要点

1. 背景1.1. 话题来源最近很多从事移动互联网和物联网开发的同学给我发邮件或者微博私信我&#xff0c;咨询推送服务相关的问题。问题五花八门&#xff0c;在帮助大家答疑解惑的过程中&#xff0c;我也对问题进行了总结&#xff0c;大概可以归纳为如下几类&#xff1a;1&#x…

莫烦Pytorch神经网络第五章代码修改

5.1动态Dynamic import torch from torch import nn import numpy as np import matplotlib.pyplot as plt# torch.manual_seed(1) # reproducible# Hyper Parameters INPUT_SIZE 1 # rnn input size / image width LR 0.02 # learning rateclass…

鲜为人知的6个黑科技网站_6种鲜为人知的熊猫绘图工具

鲜为人知的6个黑科技网站Pandas is the go-to Python library for data analysis and manipulation. It provides numerous functions and methods that expedice the data analysis process.Pandas是用于数据分析和处理的Python库。 它提供了加速数据分析过程的众多功能和方法…

VRRP网关冗余

实验要求 1、R1创建环回口&#xff0c;模拟外网 2、R2&#xff0c;R3使用VRRP技术 3、路由器之间使用EIGRP路由协议  实验拓扑  实验配置  R1(config)#interface loopback 0R1(config-if)#ip address 1.1.1.1 255.255.255.0R1(config-if)#int e0/0R1(config-if)#ip addr…

网页JS获取当前地理位置(省市区)

网页JS获取当前地理位置&#xff08;省市区&#xff09; 一、总结 一句话总结&#xff1a;ip查询接口 二、网页JS获取当前地理位置&#xff08;省市区&#xff09; 眼看2014又要过去了&#xff0c;翻翻今年的文章好像没有写几篇&#xff0c;忙真的或许已经不能成为借口了&#…

大熊猫卸妆后_您不应错过的6大熊猫行动

大熊猫卸妆后数据科学 (Data Science) Pandas is used mainly for reading, cleaning, and extracting insights from data. We will see an advanced use of Pandas which are very important to a Data Scientist. These operations are used to analyze data and manipulate…

数据eda_关于分类和有序数据的EDA

数据eda数据科学和机器学习统计 (STATISTICS FOR DATA SCIENCE AND MACHINE LEARNING) Categorical variables are the ones where the possible values are provided as a set of options, it can be pre-defined or open. An example can be the gender of a person. In the …

PyTorch官方教程中文版:PYTORCH之60MIN入门教程代码学习

Pytorch入门 import torch""" 构建非初始化的矩阵 """x torch.empty(5,3) #print(x)""" 构建随机初始化矩阵 """x torch.rand(5,3)""" 构造一个矩阵全为 0&#xff0c;而且数据类型是 long &qu…

Flexbox 最简单的表单

弹性布局(Flexbox)逐渐流行&#xff0c;越来越多的人开始使用&#xff0c;因为它写Css布局真是太简单了一一、<form>元素表单使用<form>元素<form></form>复制代码上面是一个空的表单&#xff0c;根据HTML标准&#xff0c;它是一个块级元素&#xff0c…