This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Solution to the exercise 3.18 in ML for the Working Programmer, 2nd Edition*) | |
fun deccarry (0, ps) = ps | |
| deccarry (n, []) = [n] | |
| deccarry (n, p::ps) = if (n + p) > 9 | |
then ((n+p) mod 10) :: deccarry (1 , ps) | |
else n + p :: deccarry ( 0 , ps) | |
fun decsum (c, [], qs) = deccarry (c,qs) | |
| decsum (c, ps, []) = deccarry (c,ps) | |
| decsum (c, p::ps, q::qs) = | |
((c+p+q) mod 10) :: decsum((c+p+q) div 10, ps, qs); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import | |
(chicken format) | |
srfi-18 | |
) | |
(define (fib n) | |
(fib-iter 1 0 n)) | |
(define (fib-iter a b count) | |
(if (= count 0) | |
b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# read a csv file | |
np.genfromtxt(filename,delimiter, skip_header=1) | |
# adding a scalar value to a vector result in a vector | |
# + 10 operation is applied to each value in the array | |
print(np.array([2,4,6,8]) + 10) | |
# boolean arrays are arrays of boolean values |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# create an m * n matrix | |
matrix = np.array([(2, 3 , 4), (1, 2, 3)]) | |
# create m * n zeros matrix | |
zeros = np.zeros( (1, 3) ) | |
# create m * n ones matrix, default float type |
NewerOlder