CS 231n----Assignment1 记录
记录下在完成cs231n的Assignment1过程中的一些东西。
1. scores是一个N*C的array,N是训练样本个数,C是标签。y是(N,)的数组,取出每一个样本对应的score,可以用以下的语法:
correct_score = scores[range(N), y]
2. numpy.random.choice
>>> np.random.choice(5, 3)
array([0, 3, 4])
>>> #This is equivalent to np.random.randint(0,5,3)
3. numpy.linalg.norm 计算范数的函数,包括二范数,核范数等等
4. numpy.array_split 把一个数组等分成几个小数组
>>> x = np.arange(8.0)
>>> np.array_split(x, 3)
[array([ 0., 1., 2.]), array([ 3., 4., 5.]), array([ 6., 7.])]
5. numpy里面有很多选择沿某个轴操作的函数,比如numpy.sum,numpy.argmax等函数。axis=0,表示函数操作沿列(col)进行,得到一个行向量;
axis=1,表示函数操作沿着行(row)进行,得到一个列向量。
>>> a = np.arange(6).reshape(2,3)
>>> a
array([[0, 1, 2],
[3, 4, 5]])
>>> np.argmax(a)
5
>>> np.argmax(a, axis=0)
array([1, 1, 1])
>>> np.argmax(a, axis=1)
array([2, 2])
6. numpy.hstack, numpy.vstack, numpy.stack以及numpy.concatenate 把两个或者多个数组沿某一个轴进行级联。
7. 说下最让我惊讶的python的Broadcasting。Broadcating是说两个不同维度的数组也能进行加减乘除等操作运算,当然维度不同也是有一定限制的,只是放宽了一定限制。
官网上是这么说的:When operating on two arrays, NumPy compares their shapes element-wise. It starts with the trailing dimensions, and works its way forward. Two dimensions are compatible when
- they are equal, or
- one of them is 1
举个例子:
>>> a = np.array([0.0, 10.0, 20.0, 30.0])
>>> b = np.array([1.0, 2.0, 3.0])
>>> a[:, np.newaxis] + b
array([[ 1., 2., 3.],
[ 11., 12., 13.],
[ 21., 22., 23.],
[ 31., 32., 33.]])
# Here the newaxis index operator inserts a new axis into a, making it a two-dimensional 4x1 array. Combining the 4x1 array with b, which has shape (3,), yields a 4x3 array.
numpy还有其他一些好玩的trick,参见http://anie.me/numpy-tricks/
8. np.newaxis。新增一个维度。
9. np.flatten返回对象的一个拷贝,np.ravel返回的是原对象的视图,更改之,会更改原对象
CS 231n----Assignment1 记录的更多相关文章
- IIS W3C日志记录字段和HTTP状态代码的说明
像新网的部分服务器ftp目录有这个文件,但是就是提示没权限查看也没有权限下载,还得必须给他们打电话才能要到. 做为网站拥有者,我们应该关注IIS日志,从里面我们不仅仅可以看到网站的访问记录和搜索引擎的 ...
- 斯坦福CS课程列表
http://exploredegrees.stanford.edu/coursedescriptions/cs/ CS 101. Introduction to Computing Principl ...
- Mono.Android 基础
Mono.Android 基础 (地址) Mono.Android项目结构是 — Project + Assets + Resources + drawable + layout + values R ...
- A Beginner's Guide To Understanding Convolutional Neural Networks(转)
A Beginner's Guide To Understanding Convolutional Neural Networks Introduction Convolutional neural ...
- (转)The 9 Deep Learning Papers You Need To Know About (Understanding CNNs Part 3)
Adit Deshpande CS Undergrad at UCLA ('19) Blog About The 9 Deep Learning Papers You Need To Know Abo ...
- (转)A Beginner's Guide To Understanding Convolutional Neural Networks
Adit Deshpande CS Undergrad at UCLA ('19) Blog About A Beginner's Guide To Understanding Convolution ...
- .net简单的aspx创建
在所在项目右键 --添加--新建项--web窗体 产生3个文件: hello.aspx :页面样式 hello.aspx.cs:后台方法(逻辑处理) hello.aspx.designer.cs(版 ...
- ASP.NET Zero--9.一个例子(2)商品分类管理-列表
1.创建实体类 参考:http://www.cnblogs.com/farb/p/4923137.html 在Core(领域层)项目下新建一个目录Entities,在此目录下新建一个Category类 ...
- (转)Awesome Courses
Awesome Courses Introduction There is a lot of hidden treasure lying within university pages scatte ...
- EF CodeFirst 数据库的操作
生成数据库 首先需要通过Nuget安装Migration 这一步是初始化Migration操作. 首先打开程序包控制台, 工具——NuGet包管理器——程序包管理控制台 打开后,在控制台输入下面的命令 ...
随机推荐
- 2015年我国IT行业发展趋势分析(转)
中国信息化建设步伐正持续推进,行业和企业信息化应用水平也在不断提高,这使得it技术与应用系统已成为企业日常工作中不可或缺的基础设施.与此同时,用户关注的重心也日益转向it系统的稳定性.系统对生产效率的 ...
- IE下被遮住的iframe能接收事件
今天,2012-2-22,是个很二的日子,遇到了一个诡异的问题~~ 下午收到一封信. from:someone@ctrip.comto:小灰灰title:被挡住的iframe也能接收到点击事件小灰灰, ...
- jquery checkbox的相关操作——全选、反选、获得所有选中的checkbox
1.全选 $("#btn1").click(function(){ $("input[name='checkbox']").attr("checked ...
- Torch 网络层 参数的初始化问题
Torch 网络层 参数的初始化问题 参考链接: https://github.com/Kaixhin/nninit 从 Torch 中自带的包,可以看到:https://github.com/tor ...
- (转) Awesome Deep Learning
Awesome Deep Learning Table of Contents Free Online Books Courses Videos and Lectures Papers Tutori ...
- 集群 & 负载均衡
集群(Cluster) 指一组计算机系统构成一个松耦合的多处理器系统,它们之间通过网络实现进程间的通信,实现分布式计算.在客户端看来就像是只有一个服务器.集群可以利用多个计算机进行并行计算从而获得很高 ...
- PostgreSQL的权限查询
查看哪些用户对表sns_log_member_b_aciton有哪些权限: sns_log=> \z sns_log_member_b_aciton Access privileges Sche ...
- Vigenère密码
来源 NOIP2012复赛 提高组 第一题 描述 16世纪法国外交家Blaise de Vigenère设计了一种多表密码加密算法--Vigenère密码.Vigenère密码的加密解密算法简单易用 ...
- Android 贝塞尔曲线库
最近做的一个小项目需要绘制一些折线图,AChartEngine其实里面包含很多图,虽然是开源的,但毕竟不是自己写的,而且项目稍有点庞大,有些东西修改起来还是得花点时间的,所以最后打算自己写一个,参考了 ...
- TEX学习笔记
整理在这里, 方便以后容易查找. 毕竟每个tex的模板有些不一样. Beamer: Latex beamer 学习总结 http://blog.sina.com.cn/s/blog_6cf921f30 ...