日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > 循环神经网络 >内容正文

循环神经网络

matlab accumulation,Matlab学习笔记(三)

發布時間:2023/12/9 循环神经网络 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matlab accumulation,Matlab学习笔记(三) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Array Creation and Concatenation

Create Numeric Arrays

在MATLAB中,所有的變量都是arrays,并且,默認所有的數值變量都是double類型。例如:

>> A=100

A =

100

>> whos A

Name ? ? ?Size ? ? ? ? ? ?Bytes ?Class ? ? Attributes

A ? ? ? ? 1x1 ? ? ? ? ? ? ? ? 8 ?double

為了創建一個matrix(一個二維,矩形的array),可以使用[ ] operator([ ]只能用于創建matrix,不能用于創建高維array):

B = [12, 62, 93, -8, 22; 16, 2, 87, 43, 91; -4, 17, -72, 95, 6]

B =

12 62 93 -8 22

16 2 87 43 91

-4 17 -72 95 6 當使用這個運算符時,列之間用空格或者逗號(comma)分開,行之間用分號(semicolon)分開。所有的行必須有相同的元素數目。

如果一個matrix只有一行或者只有一列,那么就叫做vector,例如:

C = [1, 2, 3]

或者

D = [10; 20; 30]

Creating and Concatenating Matrices

注意當輸入符號時,符號要在數值之前。

7 -2 +5 7 - 2 + 5

ans = ans =

10 10

上面兩個是等價的,下面兩個是不等價的:

[7 -2 +5] [7 - 2 + 5]

ans = ans =

7 -2 5 10

Specialized Matrix Functions

MATLAB中有許多函數可以創建不同的matrix:

Function

Description

Create a matrix or array of all ones.

Create a matrix or array of all zeros.

Create a matrix with ones on the diagonal and zeros elsewhere.

Distribute elements of an input matrix to specified locations in an output matrix, also allowing for accumulation.

Create a diagonal matrix from a vector.

Create a square matrix with rows, columns, and diagonals that add up to the same number.

Create a matrix or array of uniformly distributed random numbers.

Create a matrix or array of normally distributed random numbers and arrays.

Create a vector (1-by-n matrix) containing a random permutation of the specified integers. 大多數這些函數返回的矩陣類型都是double,但是可以使用ones,zeros 和eye改變數值類型,這時需要把MATLAB的類型名作為最后一個參數。例如:

A = zeros(4, 6, 'uint32')

A =

0 0 0 0 0 0

0 0 0 0 0 0

0 0 0 0 0 0

0 0 0 0 0 0 一些例子:(具體用法可以參考help文檔)

A = magic(5)

A =

17 24 1 8 15

23 5 7 14 16

4 6 13 20 22

10 12 19 21 3

11 18 25 2 9

A = [12 62 93 -8 22];

B = diag(A, -1)

B =

0 0 0 0 0 0

12 0 0 0 0 0

0 62 0 0 0 0

0 0 93 0 0 0

0 0 0 -8 0 0

0 0 0 0 22 0

Concatenating Matrices

Matrix concatenation就是把一個或者多個matrices合并成一個新的matrix。[ ] operator不僅用于matrix創建,也用于matrix concatenation。

表達式?C = [A B] horizontally concatenates matrices A and B.。表達式?C = [A; B] vertically concatenates them。

如下的例子是vertically concatenate:

A = ones(2, 5) * 6; % 2-by-5 matrix of 6's

B = rand(3, 5); % 3-by-5 matrix of random values

C = [A; B] % Vertically concatenate A and B

C =

6.0000 6.0000 6.0000 6.0000 6.0000

6.0000 6.0000 6.0000 6.0000 6.0000

0.9501 0.4860 0.4565 0.4447 0.9218

0.2311 0.8913 0.0185 0.6154 0.7382

0.6068 0.7621 0.8214 0.7919 0.1763

Keeping Matrices Rectangular

我們可以使用已知的matrix創建任意類型的matrices或者更高維的array,但是必須是合法的形狀。如下圖

如果水平(horizon)創建,那么行數必須相同,如果垂直(vertical)創建,那么列數必須相同。

下圖顯示水平創建的時候必須行數相同:

下圖顯示垂直創建的時候列數不同,MATLAB是不允許這樣的:

Matrix Concatenation Functions

Function

Description

Concatenate matrices along the specified dimension

Horizontally concatenate matrices

Vertically concatenate matrices

Create a new matrix by replicating and tiling existing matrices

Create a block diagonal matrix from existing matrices 例子:

Concatenating Matrices and Arrays.可以使用如下三個函數來替代[ ] operator:?cat, horzcat, and vertcat. 使用這些函數,可以創建任意維的arrays。

C = cat(1, A, B); % Concatenate along the first dimension

C = vertcat(A, B); % Concatenate vertically

Replicating a Matrix.repmat函數是通過復制已存在的matrix來創建新的matrix的。

repmat(M, v, h)

MATALB豎直復制矩陣M v次,水平復制h次:

A = [8 1 6; 3 5 7; 4 9 2]

A =

8 1 6

3 5 7

4 9 2

B = repmat(A, 2, 4)

B =

8 1 6 8 1 6 8 1 6 8 1 6

3 5 7 3 5 7 3 5 7 3 5 7

4 9 2 4 9 2 4 9 2 4 9 2

8 1 6 8 1 6 8 1 6 8 1 6

3 5 7 3 5 7 3 5 7 3 5 7

4 9 2 4 9 2 4 9 2 4 9 2

Creating a Block Diagonal Matrix.blkdiag函數是沿著對角線方向創建矩陣的:

A = magic(3);

B = [-5 -6 -9; -4 -4 -2];

C = eye(2) * 8;

D = blkdiag(A, B, C)

D =

8 1 6 0 0 0 0 0

3 5 7 0 0 0 0 0

4 9 2 0 0 0 0 0

0 0 0 -5 -6 -9 0 0

0 0 0 -4 -4 -2 0 0

0 0 0 0 0 0 8 0

0 0 0 0 0 0 0 8

Generating a Numeric Sequence

使用colon operator:默認是以1增長的。

A = 10:15

A =

10 11 12 13 14 15

A = -2.5:2.5

A =

-2.5000 -1.5000 -0.5000 0.5000 1.5000 2.5000

A = 1:6.3

A =

1 2 3 4 5 6 注意這里是增長的,下面的例子顯然不對:

A = 9:1

A =

Empty matrix: 1-by-0 可以改變增長的值:

A = 10:5:50

A =

10 15 20 25 30 35 40 45 50

A = 3:0.2:3.8

A =

3.0000 3.2000 3.4000 3.6000 3.8000

A = 9:-1:1

A =

9 8 7 6 5 4 3 2 1

總結

以上是生活随笔為你收集整理的matlab accumulation,Matlab学习笔记(三)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。