Skip to content

習題:陣列函數的練習 #5

Description

@ccckmit

請寫出下列函數與測試程式:

一維矩陣

  1. 請算出某陣列的平均值?
    • 範例: mean([1,2,3,4,5]) => 3
  2. 算出某陣列的標準差? (標準差為 (xi-x)^2 的總和)
    • 範例: sd([1,2,3,4,5]) = sqrt((2^2+1^2+0^2+1^2+2^2)/5) = sqrt(2)=1.414。
  3. 寫一個程式做因數分解。
    • 範例:factor(45) => [3, 3, 5]

二維矩陣

  1. 請寫一個函數計算兩矩陣相加?
    • 範例: add([[1,2],[3,4]], [[1,1],[1,1]]) => [[2,3], [4,5]]
  2. 請寫一個函數 neg(A) 傳回某矩陣 A 的負矩陣 -A。
    • 範例: neg([[1,2],[3,4]]) => [[-1,-2],[-3,-4]]
  3. 寫一個程式把矩陣轉置。
    • 範例:transpose([[1,2,3], [3,2,1]]) => [[1,3], [2,2], [3,1]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions