记录下在完成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

  1. they are equal, or
  2. 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 记录的更多相关文章

  1. IIS W3C日志记录字段和HTTP状态代码的说明

    像新网的部分服务器ftp目录有这个文件,但是就是提示没权限查看也没有权限下载,还得必须给他们打电话才能要到. 做为网站拥有者,我们应该关注IIS日志,从里面我们不仅仅可以看到网站的访问记录和搜索引擎的 ...

  2. 斯坦福CS课程列表

    http://exploredegrees.stanford.edu/coursedescriptions/cs/ CS 101. Introduction to Computing Principl ...

  3. Mono.Android 基础

    Mono.Android 基础 (地址) Mono.Android项目结构是 — Project + Assets + Resources + drawable + layout + values R ...

  4. A Beginner's Guide To Understanding Convolutional Neural Networks(转)

    A Beginner's Guide To Understanding Convolutional Neural Networks Introduction Convolutional neural ...

  5. (转)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 ...

  6. (转)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 ...

  7. .net简单的aspx创建

    在所在项目右键 --添加--新建项--web窗体 产生3个文件: hello.aspx  :页面样式 hello.aspx.cs:后台方法(逻辑处理) hello.aspx.designer.cs(版 ...

  8. ASP.NET Zero--9.一个例子(2)商品分类管理-列表

    1.创建实体类 参考:http://www.cnblogs.com/farb/p/4923137.html 在Core(领域层)项目下新建一个目录Entities,在此目录下新建一个Category类 ...

  9. (转)Awesome Courses

    Awesome Courses  Introduction There is a lot of hidden treasure lying within university pages scatte ...

  10. EF CodeFirst 数据库的操作

    生成数据库 首先需要通过Nuget安装Migration 这一步是初始化Migration操作. 首先打开程序包控制台, 工具——NuGet包管理器——程序包管理控制台 打开后,在控制台输入下面的命令 ...

随机推荐

  1. 随机函数的代码(srand、rand)

    #include<stdio.h> int main() int counter; for(counter=0;counter<10;counter++) { srand(count ...

  2. NHibernate使用Access数据库的配置问题

    NHibernate本身不支持Access数据库,一开始看网上各种文档,捣敲浪费了N分钟. 还是祭起Nuget神器引用NHibernate.JetDrive. 代码如下,搞定收工... private ...

  3. 00 alv抬头等

    *&---------------------------------------------------------------------* *& Report ZHJ_TEST0 ...

  4. 在线markdown编辑器

    https://www.zybuluo.com/mdeditor http://mahua.jser.me/

  5. 【组合数学】 02 - Möbius反演公式

    计数问题种类繁多,为了避免陷入漫无目的烧脑运动,我们先需要关注一些常用方法和结论.数学的抽象性和通用性是我们一直推崇的,从诸多特殊问题中发现一般性的方法,也总会让人兴奋和慨叹.一般教材多是以排列组合开 ...

  6. C#中的属性太邪恶了

    好懒,啥都不想写了.C#的属性伤透了我的心.只能相信记忆力和想象力能让我下次翻到这篇日志时能瞬间想到我们在谈瓦特. http://stackoverflow.com/questions/1224270 ...

  7. 6个强大的AngularJS扩展应用

    本文链接:http://www.codeceo.com/article/6-angularjs-extension.html本文作者:码农网 – 小峰 AngularJS现在非常热门,是Google推 ...

  8. PetShop安装失败

    报错提示: Security This installer has encountered an unexpected error installing this package. This may ...

  9. 承接Hololens游戏外包

    近日,微软宣布第三批微软Hololens开发者版开始发货,包括:头显.头显手提包和一个遥控器.前两批开发者版本分别在今年3月30日和5月9日开始发货的. 第三批AR头显Hololens开发者版发货 虽 ...

  10. 使用图灵机器人API实现聊天机器人

    使用图灵机器人的API需要先注册,获取key才行,这我就不说了,自己到http://www.tuling123.com/注册一个账号即可. 下面就是一个简单的python调用API实现聊天机器人的简易 ...