plus .+
minus .-
times .*
rdivide ./
ldivide .\
power .^ .**
https://www.gnu.org/software/octave/doc/v4.0.0/Arithmetic-Ops.html#Arithmetic-Ops
x .+ y
Element-by-element addition. This operator is equivalent to +.
x = [1 2 3;
4 5 6;
7 8 9]
y = [1 1 1;
1 1 1;
1 1 1]
x.+y # equal x+y, because + originally is a element by element operator
ans =
2 3 4
5 6 7
8 9 10
x .* y
Element-by-element multiplication. If both operands are matrices, the number of rows and columns must both agree, or they must be broadcastable to the same shape.
x = [1 2 3;
4 5 6;
7 8 9]
y = [10 2 1;
10 2 1;
10 2 1]
x*y #normal *
ans =
60 12 6
150 30 15
240 48 24
x.*y # element by element 1*10 4*10 7*10 .....
ans =
10 4 3
40 10 6
70 16 9
x ./ y
Element-by-element right division.
x = [1 2 3;
4 5 6;
7 8 9]
y = [10 2 1;
10 2 1;
10 2 1]
x./y
ans =
0.10000 1.00000 3.00000
0.40000 2.50000 6.00000
0.70000 4.00000 9.00000
y = [10 2 1;
10 2 1;
10 2 1]
m=5
y./5 # equal y/5
ans =
2.00000 0.40000 0.20000
2.00000 0.40000 0.20000
2.00000 0.40000 0.20000
利用 Python,R,Excel VBA,multicharts 自造決策中心,取得量化交易能力, 再利用資訊不對稱,站在對你有利的這邊。
2016年5月23日 星期一
[octave]broadcasting
https://www.gnu.org/software/octave/doc/v4.0.0/Broadcasting.html#Broadcasting
在octave 中, broadcasting 的意思是
當兩個唯度不同矩陣要運算時, 維度小的 會自己擴充成跟維度大的一樣維度之後, 才進行運算
ex:
x = [1 2 3;
4 5 6;
7 8 9]
y = [10 20 30]
x+y # 這本來是不能作的, 因為x y 維度不同, 但他自動幫你變成
這就是broadcasting, 此時 y 維度就跟x 一樣, 可以作加法了
>>output
warning: operator +: automatic broadcasting operation applied
ans =
11 22 33
14 25 36
17 28 39
(他也會出現警告, 提醒你這個+法經過了broadcasting)
如果兩個matrix 一樣dimension , 則直接就是
element by element 相加
x = [1 2 3;
4 5 6;
7 8 9]
y = [1 2 3;
4 5 6;
7 8 9]
x+y
ans =
2 4 6
8 10 12
14 16 18
在octave 中, broadcasting 的意思是
當兩個唯度不同矩陣要運算時, 維度小的 會自己擴充成跟維度大的一樣維度之後, 才進行運算
ex:
x = [1 2 3;
4 5 6;
7 8 9]
y = [10 20 30]
x+y # 這本來是不能作的, 因為x y 維度不同, 但他自動幫你變成
y = [10 20 30
10 20 30
10 20 30];
這就是broadcasting, 此時 y 維度就跟x 一樣, 可以作加法了
>>output
warning: operator +: automatic broadcasting operation applied
ans =
11 22 33
14 25 36
17 28 39
(他也會出現警告, 提醒你這個+法經過了broadcasting)
如果兩個matrix 一樣dimension , 則直接就是
element by element 相加
x = [1 2 3;
4 5 6;
7 8 9]
y = [1 2 3;
4 5 6;
7 8 9]
x+y
ans =
2 4 6
8 10 12
14 16 18
[octave ] octave zeros function
Built-in Function: zeros (n)
Built-in Function: zeros (m, n)
Built-in Function: zeros (m, n, k, …)
Built-in Function: zeros ([m n …])
Built-in Function: zeros (…, class)
Return a matrix or N-dimensional array whose elements are all 0.
If invoked with a single scalar integer argument, return a square NxN matrix.
If invoked with two or more scalar integer arguments, or a vector of integer values, return an array with the given dimensions.
The optional argument class specifies the class of the return array and defaults to double. For example:
val = zeros (m,n, "uint8")
a=[1, 2, 33;4 ,5, 6; 7 ,8, 66;55 ,476, 22]
a =
1 2 33
4 5 6
7 8 66
55 476 22
[rows columns]=size(a);
rows = 4
columns = 3
zeros (rows,columns, "uint8")
ans =
0 0 0
0 0 0
0 0 0
0 0 0
zeros(4) # will give you 4x4 matrix
ans =
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
zeros(4,1) #want a 4x1 zero vector
ans =
0
0
0
0
Built-in Function: zeros (m, n)
Built-in Function: zeros (m, n, k, …)
Built-in Function: zeros ([m n …])
Built-in Function: zeros (…, class)
Return a matrix or N-dimensional array whose elements are all 0.
If invoked with a single scalar integer argument, return a square NxN matrix.
If invoked with two or more scalar integer arguments, or a vector of integer values, return an array with the given dimensions.
The optional argument class specifies the class of the return array and defaults to double. For example:
val = zeros (m,n, "uint8")
a=[1, 2, 33;4 ,5, 6; 7 ,8, 66;55 ,476, 22]
a =
1 2 33
4 5 6
7 8 66
55 476 22
[rows columns]=size(a);
rows = 4
columns = 3
zeros (rows,columns, "uint8")
ans =
0 0 0
0 0 0
0 0 0
0 0 0
zeros(4) # will give you 4x4 matrix
ans =
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
zeros(4,1) #want a 4x1 zero vector
ans =
0
0
0
0
[octave] size function
size function
https://www.gnu.org/software/octave/doc/v4.0.1/Object-Sizes.html#XREFsize
Built-in Function: size (a)
Built-in Function: size (a, dim)
Return the number of rows and columns of a.
With one input argument and one output argument, the result is returned in a row vector. If there are multiple output arguments, the number of rows is assigned to the first, and the number of columns to the second, etc. For example:
size ([1, 2; 3, 4; 5, 6])
⇒ [ 3, 2 ]
[nr, nc] = size ([1, 2; 3, 4; 5, 6])
⇒ nr = 3
⇒ nc = 2
If given a second argument, size will return the size of the corresponding dimension. For example,
size ([1, 2; 3, 4; 5, 6], 2)
⇒ 2
returns the number of columns in the given matrix.
Testing:
a=[1, 2, 33;4 ,5, 6; 7 ,8, 66;55 ,476, 22]
a =
1 2 33
4 5 6
7 8 66
55 476 22
[rows columns]=size(a);
rows = 4
columns = 3
size(a,1) # 1 means get rows ; 2 means get columns
ans = 4
size(a,2)
ans = 3
-------------------------------------------------------------------------------
https://www.gnu.org/software/octave/doc/v4.0.1/Object-Sizes.html#XREFsize
Built-in Function: size (a)
Built-in Function: size (a, dim)
Return the number of rows and columns of a.
With one input argument and one output argument, the result is returned in a row vector. If there are multiple output arguments, the number of rows is assigned to the first, and the number of columns to the second, etc. For example:
size ([1, 2; 3, 4; 5, 6])
⇒ [ 3, 2 ]
[nr, nc] = size ([1, 2; 3, 4; 5, 6])
⇒ nr = 3
⇒ nc = 2
If given a second argument, size will return the size of the corresponding dimension. For example,
size ([1, 2; 3, 4; 5, 6], 2)
⇒ 2
returns the number of columns in the given matrix.
Testing:
a=[1, 2, 33;4 ,5, 6; 7 ,8, 66;55 ,476, 22]
a =
1 2 33
4 5 6
7 8 66
55 476 22
[rows columns]=size(a);
rows = 4
columns = 3
size(a,1) # 1 means get rows ; 2 means get columns
ans = 4
size(a,2)
ans = 3
-------------------------------------------------------------------------------
[Octave] Octave matrix slice
CASE1:
a=[1, 2, 33;4 ,5, 6; 7 ,8, 66];
a =
1 2 33
4 5 6
7 8 66
a(3) # result is a scalar
ans = 7
a(1:4) # show range form index 1 to(:) index 4, and result is a row vector
ans =
1 4 7 2
a([1; 9]) # show range form index 1 and index 9 result is a column vector
ans =
1
66
a(1, [1, 3]) # row 1, columns 1 and 3
ans =
1 33
a(3, 1:3) # row 3, columns in range 1-2
ans =
7 8 66
a(1, :) # row 1, all columns , use really often !!!
ans =
1 2 33
Case2:
a = [1, 2, 3, 4]
a =
1 2 3 4
a(1:end/2) # first half of a => [1, 2],end is the last element in the matrix
ans =
1 2
a(end + 1) =5 # append element
a =
1 2 3 4 5
a(end) = [] # delete element
a =
1 2 3 4
a(1:2:end) # odd elements of a => [1, 3]
ans =
1 3
a(2:2:end) # even elements of a => [2, 4]
ans =
2 4
a(end:-1:1) # reversal of a => [4, 3, 2 , 1]
ans =
4 3 2 1
CASE3: often use in machine learning cost function
a=[1, 2, 33;4 ,5, 6; 7 ,8, 66];
a =
1 2 33
4 5 6
7 8 66
[99 ; a(1,:)']
ans =
99
1
2
33
num_labels=4;
zeros(num_labels,1)
ans =
0
0
0
0
a=[1, 2, 33;4 ,5, 6; 7 ,8, 66;55 ,476, 22]
a =
1 2 33
4 5 6
7 8 66
55 476 22
a(:,2:end) #from second column to end
ans =
2 33
5 6
8 66
476 22
a(1,:) #get first row
ans =
1 2 33
a(2:end) # start from element 2 to end
ans =
4 7 55 2 5 8 476 33 6 66 22
a(:) # unroll every element
ans =
1
4
7
55
2
5
8
476
33
6
66
a=[1, 2, 33;4 ,5, 6; 7 ,8, 66];
a =
1 2 33
4 5 6
7 8 66
a(3) # result is a scalar
ans = 7
a(1:4) # show range form index 1 to(:) index 4, and result is a row vector
ans =
1 4 7 2
a([1; 9]) # show range form index 1 and index 9 result is a column vector
ans =
1
66
a(1, [1, 3]) # row 1, columns 1 and 3
ans =
1 33
a(3, 1:3) # row 3, columns in range 1-2
ans =
7 8 66
a(1, :) # row 1, all columns , use really often !!!
ans =
1 2 33
Case2:
a = [1, 2, 3, 4]
a =
1 2 3 4
a(1:end/2) # first half of a => [1, 2],end is the last element in the matrix
ans =
1 2
a(end + 1) =5 # append element
a =
1 2 3 4 5
a(end) = [] # delete element
a =
1 2 3 4
a(1:2:end) # odd elements of a => [1, 3]
ans =
1 3
a(2:2:end) # even elements of a => [2, 4]
ans =
2 4
a(end:-1:1) # reversal of a => [4, 3, 2 , 1]
ans =
4 3 2 1
CASE3: often use in machine learning cost function
a=[1, 2, 33;4 ,5, 6; 7 ,8, 66];
a =
1 2 33
4 5 6
7 8 66
[99 ; a(1,:)']
ans =
99
1
2
33
num_labels=4;
zeros(num_labels,1)
ans =
0
0
0
0
a=[1, 2, 33;4 ,5, 6; 7 ,8, 66;55 ,476, 22]
a =
1 2 33
4 5 6
7 8 66
55 476 22
a(:,2:end) #from second column to end
ans =
2 33
5 6
8 66
476 22
a(1,:) #get first row
ans =
1 2 33
a(2:end) # start from element 2 to end
ans =
4 7 55 2 5 8 476 33 6 66 22
a(:) # unroll every element
ans =
1
4
7
55
2
5
8
476
33
6
66
2016年5月9日 星期一
2016年5月3日 星期二
[octave] build octave under sublime text 3 (pause not work)
tools->build system->new build system
{
"path": "/usr/bin/",//path of your Octave bin folder
"cmd": ["octave", "--no-site-file", "-p $file_path", "$file_name"]
}
{
"path": "/usr/bin/",//path of your Octave bin folder
"cmd": ["octave", "--no-site-file", "-p $file_path", "$file_name"]
}
標籤:
IDE,
Machine Learning
訂閱:
文章 (Atom)