[Machine Learning] Octave Computing on Data
Mutiplate materix:
Everytime you see '.' mean element wise operator.
>> A = [1 2; 3 4; 5 6]; >> B = [11 12; 13 14; 15 16]; >> C = [1 1; 2 2]; >> A*C ans = 5 5 11 11 17 17 >> A .* B # each element of A & B (1*11=11) ans = 11 24 39 56 75 96
>> A .^ 2
ans =
1 4
9 16
25 36
>> 1 ./ A
ans =
1.00000 0.50000
0.33333 0.25000
0.20000 0.16667
>> v = [1; 2; 3] v = 1 2 3 >> log(v) ans = 0.00000 0.69315 1.09861 >> exp(v) ans = 2.7183 7.3891 20.0855
>> abs(v) ans = 1 2 3 >> -v ans = -1 -2 -3
Increase v element all by 1:
>> v + ones(length(v), 1) ans = 2 3 4 """ >> length(v) ans = 3 >> ones(3, 1) ans = 1 1 1 """
or
>> v + 1
ans =
2
3
4
Transposed:
>> A A = 1 2 3 4 5 6 >> A' ans = 1 3 5 2 4 6
Max for vector:
>> a= [1 15 2 0.5] a = 1.00000 15.00000 2.00000 0.50000 >> val = max(a) val = 15 >> [val, ind] = max(a) val = 15 ind = 2
Max for materix: column wise max value
>> A A = 1 2 3 4 5 6 >> max(A) ans = 5 6
>> A A = 8 1 6 3 5 7 4 9 2 >> max(A, [], 1) # column wise max value ans = 8 9 7 >> max(A, [], 2) # row wise max value ans = 8 7 9
If you want to find the max value of the whole matrix:
>> max(max(A)) ans = 9 >> max(A(:)) ans = 9
Logic:
>> a a = 1.00000 15.00000 2.00000 0.50000 >> a < 3 ans = 1 0 1 1
find: find all the indexs match the conds:
>> find(a < 3)
ans =
1 3 4
Magic materix:
>> A = magic(3) A = 8 1 6 3 5 7 4 9 2 >> [r, c] = find(A > 7) r = 1 3 c = 1 2
A(1, 1) A(3, 2) have the element which larger than 7
Sum:
>> sum(a) ans = 18.500 >> prod(a) ans = 15 >> floor(a) ans = 1 15 2 0 >> ceil(a) ans = 1 15 2 1
Column wise sum:
>> A = magic(9) A = 47 58 69 80 1 12 23 34 45 57 68 79 9 11 22 33 44 46 67 78 8 10 21 32 43 54 56 77 7 18 20 31 42 53 55 66 6 17 19 30 41 52 63 65 76 16 27 29 40 51 62 64 75 5 26 28 39 50 61 72 74 4 15 36 38 49 60 71 73 3 14 25 37 48 59 70 81 2 13 24 35 >> sum(A, 1) ans = 369 369 369 369 369 369 369 369 369
row wise sum:
>> sum(A, 2)
ans =
369
369
369
369
369
369
369
369
369
Diagonal sum:
>> A .* eye(9). # only get diagonal values ans = 47 0 0 0 0 0 0 0 0 0 68 0 0 0 0 0 0 0 0 0 8 0 0 0 0 0 0 0 0 0 20 0 0 0 0 0 0 0 0 0 41 0 0 0 0 0 0 0 0 0 62 0 0 0 0 0 0 0 0 0 74 0 0 0 0 0 0 0 0 0 14 0 0 0 0 0 0 0 0 0 35 >> sum(sum(A .* eye(9))) ans = 369
Other way around:
>> A .*flipud(eye(9)) ans = 0 0 0 0 0 0 0 0 45 0 0 0 0 0 0 0 44 0 0 0 0 0 0 0 43 0 0 0 0 0 0 0 42 0 0 0 0 0 0 0 41 0 0 0 0 0 0 0 40 0 0 0 0 0 0 0 39 0 0 0 0 0 0 0 38 0 0 0 0 0 0 0 37 0 0 0 0 0 0 0 0
Inverse:
>> A = magic(3); >> temp = pinv(A) temp = 0.147222 -0.144444 0.063889 -0.061111 0.022222 0.105556 -0.019444 0.188889 -0.102778 >> temp * A ans = 1.00000 0.00000 -0.00000 -0.00000 1.00000 0.00000 0.00000 0.00000 1.00000 # A' * A = I
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2018-08-17 [React] Build a slide deck with mdx-deck using Markdown + React
2018-08-17 [React] Spread Component Props in JSX with React
2017-08-17 [React] Create component variations in React with styled-components and "extend"
2017-08-17 [React] Animate your user interface in React with styled-components and "keyframes"
2017-08-17 [Angular] Update FormArray with patchValue
2016-08-17 [Webpack] Use the Webpack Dashboard to Monitor Webpack Operations
2016-08-17 [RxJS] AsyncSubject