-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
layout: post | ||
title: "Numpy axis intuiation" | ||
date: 2018-03-29 21:25:50 +0800 | ||
categories: math numpy | ||
--- | ||
|
||
|
||
Axis play a key in Numpy array operations, | ||
it indicate the dimension of an array(or a tensor), for example, if an array have shape (2,4,6) | ||
first dimension is axis=0 coresponding to shape 2, second dimension is axis=1 coresponding to shape 4, etc, and for the convience, Numpy also can use axis=-1 to indicate the last dimension. | ||
|
||
I made an animation for intuiation. | ||
|
||
|
||
![]({{ site.url }}/assets/article_images/2018-03-29-Numpy_axis_intuiation/s1.gif){:height="75%" width="75%"} | ||
|
||
|
||
Functions in Numpy to operate array can be classified by how to change dimensions. | ||
1. keep dimensions | ||
2. collapse dimensions | ||
3. expand dimensions | ||
4. switch axis | ||
|
||
Here is a animation shows how to operate array along different axis when keep/collapse dimensions. | ||
|
||
![s2]({{ site.url }}/assets/article_images/2018-03-29-Numpy_axis_intuiation/s2.gif){:height="75%" width="75%"} | ||
|
||
For expand and sitch axis it is almost the same idea. Numpy doc example expain this very well. | ||
|
||
|
||
||| | ||
|:----------|:----------| | ||
| [`expand_dims`](https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.expand_dims.html#numpy.expand_dims "numpy.expand_dims")(a, axis) | Expand the shape of an array. | | ||
| [`swapaxes`](https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.swapaxes.html#numpy.swapaxes "numpy.swapaxes")(a, axis1, axis2) | Interchange two axes of an array. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
layout: post | ||
title: "Numpy axis 直观印象" | ||
date: 2018-03-29 21:25:50 +0800 | ||
categories: math numpy | ||
--- | ||
|
||
Axis在Numpy库的array操作中起了非常关键的作用, 它用于指示一个array(或者说tersor)的维度. | ||
|
||
例如: 一个array的shape是(2,4,6), 那么第一个维度也就是axis=0对应的是shape 2, 第二个维度axis=1对应的是shape 4, 以此类推, 另外为了方便, axis=-1是值得倒数第一个维度. | ||
|
||
这里有个动画可以直观感受下axis | ||
|
||
![]({{ site.url }}/assets/article_images/2018-03-29-Numpy_axis_intuiation/s1.gif){:height="75%" width="75%"} | ||
|
||
Numpy中的函数可以根据对dimension的操作分为下面几类 | ||
1. dimension保持不变 | ||
2. dimension减少 | ||
3. dimension增加 | ||
4. axis交换 | ||
|
||
下面的动画展示了Numpy是如何沿着axis进行保持和减少dimension操作的 | ||
|
||
![s2]({{ site.url }}/assets/article_images/2018-03-29-Numpy_axis_intuiation/s2.gif){:height="75%" width="75%"} | ||
|
||
对于dimension增加和axis交换, 可以看下Numpy doc的例子, 动画太难做了┑( ̄Д  ̄)┍ | ||
|
||
||| | ||
|:----------|:----------| | ||
| [`expand_dims`](https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.expand_dims.html#numpy.expand_dims "numpy.expand_dims")(a, axis) | Expand the shape of an array. | | ||
| [`swapaxes`](https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.swapaxes.html#numpy.swapaxes "numpy.swapaxes")(a, axis1, axis2) | Interchange two axes of an array. | |