Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func cal(X: [Int], Y: [Int64]) -> Double {
- let total = Double(Y.reduce(0, +))
- var z = zip(X, Y).map { pow(Double($0), 2) * Double($1) }.reduce(0, +) / Double(total)
- return z
- }
- func cal(xs: [Int], ys: [Int64]) -> Double {
- let xs = xs.lazy.map(Double.init)
- let ys = ys.lazy.map(Double.init)
- let total = ys.reduce(0, +)
- return zip(xs, ys).map { $0*$0 * $1 }.reduce(0, +) / total
- }
- extension Sequence where Element: Numeric {
- func sum() -> Element {
- return reduce(0, +)
- }
- }
- func cal(xs: [Int], ys: [Int64]) -> Double {
- let xs = xs.lazy.map(Double.init)
- let ys = ys.lazy.map(Double.init)
- let total = ys.sum()
- return zip(xs, ys).map { $0*$0 * $1 }.sum() / total
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement