记录下在完成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. k8s dns 服务安装配置说明

    1. 提前条件 安装k8s 集群 2.  dns  安装配置 安装方式: 使用controller  service controller  脚本: 基于官方改动 apiVersion: v1 kin ...

  2. CNC Fanuc 设备数据采集

    为了这个Fanuc(发那科)数控机床数据的采集也花费了不少精力,先是去供应商那里了解,基本都是代理商,没有技术支持. 在网上也有关于Fanuc的以太网Ethernet连接文档,那里面有说明,大概是开发 ...

  3. 关于eclipse保存代码很慢,提示the user operation is waiting的问题

    关于eclipse保存代码很慢,提示the user operation is waiting的问题 首先 去掉 project - build Automaticlly 然后 project-> ...

  4. 使用异步I/O大大提高应用程序的性能

    转自:https://www.ibm.com/developerworks/cn/linux/l-async/ AIO简介 Linux中最常见的输入输出(I/O)模型是同步I/O.在这个模型中,当请求 ...

  5. SerializableDictionary-一个支持序列化与反序列化的Dictionary

    使用Dictionary存储的信息在试图序列化为XML保存到文件时,会遇到无法序列化的问题,由于官方Dictionary不支持xml序列化,所以有朋友已经通过实现IXmlSerializable接口, ...

  6. Mapcontrol 遍历所有图层方法

    mapcontrol 遍历所有图层方法 2011-04-29 19:51 通过IMap中的get_layers()可以遍历MapControl中当前的图层.此方法可以通过指定UID对图层进行过滤或者分 ...

  7. laravel/lumen 单元测试

    Testing Introduction Application Testing Interacting With Your Application Testing JSON APIs Session ...

  8. ES6特性

    一.ES6特性: let, const, class, extends, super, arrow functions, template string, destructuring, default ...

  9. Visual Studio并发Qpar优化效果

    IOCP客户端的connect线程FOR循环中添加强制并行,1万/S并发connect+send+recv+close,任务管理器使用从60%降到20%. Visual Studio性能监控CPU使用 ...

  10. sql server 跨数据库插入数据

    创建服务器的连接,创建好后可以存在服务器上,可以在不同位置重复使用,和系统函数类似 exec sp_addlinkedserver 'RemoteServer', '', 'SQLOLEDB ', ' ...