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包管理器——程序包管理控制台 打开后,在控制台输入下面的命令 ...
随机推荐
- EXT.net DateField format设置
DateField df = new DateField(); df.Format = "yyyy-MM-dd HH:mm:ss";格 ...
- http请求报错
手机端上传base64位图片java后台接受 手机端post方式发送 后台报错: Error parsing HTTP request header Note: further occurrences ...
- IDEA创建maven项目使用命令打包遇到的问题及解决方法
maven项目命令打包springboot项目 首先打开tomcat命令工具(如图所示):
- python之元编程(元类实例)
本实例是元类实例,功能是记录该的子类的类名,并以树状结构展示子类的类名. RegisterClasses继承自type,提供的功能是在__init__接口,为类创建了childrens的集合,并类名保 ...
- mfc打开程序
void CMy3MFCDlg::OnBnClickedButton1() { // TODO: 在此添加控件通知处理程序代码 HINSTANCE hRslt = ShellExecute(NULL, ...
- 一种扩大View点击范围的方法
Rect rect = new Rect();mBt0.getHitRect(rect); rect.bottom += 400; TouchDelegate touchDelegate = new ...
- SQL JOIN的用法
背景:(血的教训) 非常感谢能够有幸的去活力世纪面试,面试官非常的祥和,虽然最后没能够去成,但是非常的感谢,是他让我明白了自己还有很多需要去学习,每一次的面试不是为了去证明自己有多强,能拿多少的工资, ...
- HBase 常用Shell命令
两个月前使用过hbase,现在最基本的命令都淡忘了,留一个备查~ 进入hbase shell console$HBASE_HOME/bin/hbase shell如果有kerberos认证,需要事先使 ...
- oracle基础备份和还原
#全库备份 buffer inctype=complete file=c:\mminfo.dmp log=c:\mminfo.log #用户备份:用户mminfo下的所有表 buffer owner= ...
- 那些年蹚过的坑(c++)
1 main中的参数 尽量用英文双引号括起来,否则可能会出现字符串截断的情况(linux gcc 4.4 不加英文引号的话,遇到英文;会丢弃;后面的部分) 2 包含ipv6地址结构体(in6_addr ...