当前位置:网站首页>tensorflow2.X实战系列softmax函数
tensorflow2.X实战系列softmax函数
2022-07-23 12:55:00 【TJMtaotao】
softmax 原理
斯坦福大学CS224n课程中softmax的解释:

代码知识点
1、NumPy数组是一个多维数组对象,称为ndarray。数组的下标从0开始,同一个NumPy数组中所有元素的类型必须是相同的。
2、数组
数组(Array)是有序的元素序列。
若将有限个类型相同的变量的集合命名,那么这个名称为数组名。组成数组的各个变量称为数组的分量,也称为数组的元素,有时也称为下标变量。用于区分数组的各个元素的数字编号称为下标。
数组是在程序设计中,为了处理方便, 把具有相同类型的若干元素按有序的形式组织起来的一种形式。
这些有序排列的同类数据元素的集合称为数组。
3、数组与矩阵
矩阵(Matrix)是一个按照长方阵列排列的复数或实数集合,最早来自于方程组的系数及常数所构成的方阵。
矩阵是二维数据组成的
4、数组与矩阵的区别
矩阵中的元素只能是数字,而数组中的元素可以是字符或者字符串
矩阵是二维的,数组可以是一维的、多维的
矩阵显示时,元素之间无逗号;数组显示时,元素之间用逗号隔开
代码实现
import numpy
import math
def softmax(inMatrix):
m,n = numpy.shape(inMatrix) #m行,n列
outMatrix = numpy.mat(numpy.zeros((m,n))) #创建输出矩阵 通过numpy.mat
soft_sum = 0 #分母
for idx in range(0,n):
outMatrix[0,idx] = math.exp(inMatrix[0,idx])
soft_sum += outMatrix[0,idx]
for idx in range(0,n): #分子
outMatrix[0,idx] = outMatrix[0,idx] / soft_sum
return outMatrix
a = numpy.array([[0.2,0.5,0.1,0.1,0.1]]) #1x5的数组
a_softmax_output = softmax(a)
print(a_softmax_output)
输出结果
[[0.19745789 0.26654027 0.17866728 0.17866728 0.17866728]]
代码参考 Tensorflow 2.0深度学习从零开始学 王晓华著
其他参考
https://blog.csdn.net/lz_peter/article/details/84574716
https://blog.csdn.net/github_36669230/article/details/78038756
https://blog.csdn.net/weixin_44515978/article/details/107889672
边栏推荐
- Une solution complète au problème du sac à dos dans la programmation dynamique
- 基于APISIX的basic-auth插件对Minio文件上传功能进行授权
- 20220721挨揍内容
- Differences between LRU and LFU elimination strategies in redis
- 7月HCIP Datacom认证考试通过
- 【Error】TypeError: expected str, bytes or os.PathLike object, not int
- 知道为什么PCBA电路板会板翘吗?
- Go 接口:深入内部原理
- Calendar日历类
- Stm32f103+rfid-rc522 module realizes simple card reading and writing demo "recommended collection"
猜你喜欢

Oracle中实现删除指定查询条件的所有数据

移动端H5 - 手撸一个生命线 timeline

Surface family purchase reference

国产AI蛋白质结构预测再现突破,用单条序列解决3D结构,彭健团队:“AlphaFold2以来最后一块拼图补齐了”...
![[2022 freshmen learning] key points of the second week](/img/5f/87a30e898b4450af5f2eb0cf77e035.png)
[2022 freshmen learning] key points of the second week

【Error】TypeError: expected str, bytes or os.PathLike object, not int

华为新版Datacom认证介绍

20220721挨揍内容

百度编辑器上传图片设置自定义目录
![[note] linear regression](/img/71/7c1255e94f08cc0eab2ca32977f29d.png)
[note] linear regression
随机推荐
Thermal resistance temperature acquisition based on USB data acquisition card (DAQ) and IO module "suggestions collection"
Study note 7 -- traffic environment behavior prediction
Go 接口:深入内部原理
Dynamic programming knapsack problem 01 knapsack explanation
AWS Part 1
mysql的常见问题
Hcip datacom certification examination passed in July
MySQL multi table query_ Cartesian product_ Inner connection_ Implicit connection
学习笔记7--交通环境行为预测
pytest接口自动化测试框架 | 如何获取帮助
2022-7-22 面经复习+简单题目整理
O3DF执行董事Royal O’Brien:开源没有边界,所有共享的声音都会变成实际方向
竞赛大佬在华为:网络专家出身斯坦福物理系,还有人“工作跟读博差不多”...
网络协议与攻击模拟:wireshark使用、ARP协议
FreeRTOS个人笔记-延时函数
VMware platform STS certificate expired
Squid 代理服务之透明代理服务器架构搭建
Go interface: go deep into internal principles
pytest接口自动化测试框架 | 控制测试用例执行
Une solution complète au problème du sac à dos dans la programmation dynamique