Mais conteúdo relacionado Semelhante a 関数プログラマから見たPythonと機械学習 (20) Mais de Masahiro Sakai (20) 関数プログラマから見たPythonと機械学習8. •
– R MATLAB
•
– numpy/scipy, pandas, scikit-learn, matplotlib, Jupyter
Notebook,
–
9. Python
• ……
Python
• ) numpy.array ==
– numpy …
– Python
⇒
– sorted([np.zeros(2), np.zeros(2)])
• ( collections-extended
RangeMap )
10. : ……
• ……
•
……
• ) pandas itertuples
type(next(pd.DataFrame({"x" + str(i): [i] for i in range(253)}).itertuples()))
#=> pandas.core.frame.Pandas
type(next(pd.DataFrame({"x" + str(i): [i] for i in range(254)}).itertuples()))
#=> tuple
12. : Lisp-1
•
– Scheme, JavaScript
– Common Lisp, Ruby Lisp-2 ( )
•
Python Ruby
obj.foo(args) obj.foo(args)
( ) obj.foo() obj.foo(), obj.foo
obj.foo obj.method(:foo)
m(args) m.call(args), m[args]
13. : Lisp-1
• ……
→
→
• Ruby Lisp-2
•
•
Python Ruby
obj.foo(…) obj.foo(…), obj.foo …
( ) obj.foo() obj.foo(), obj.foo
obj.foo obj.method(:foo)
m(…) m.call(…), m[…]
14. • (PEP 484)
• mypy
def greeting(name: str) -> str:
return 'Hello ' + name
print(greeting(0))
# => error: Argument 1 to "greeting" has incompatible
type "int"; expected "str"
16. • (gradual typing)
– (dynamic typing) (static typing)
– Jeremy G. Siek and Walid Taha, Gradual Typing for Functional Languages, in
Proceedings of the 2006 Scheme and Functional Programming Workshop
•
– dynamic type: Any … Any
– type consistency relation: A B
• A = B Any
( : int→Any Any→str)
–
int ⊑ Any ⊑ str
•
(1)
17. (2)
•
– Python (mypy), TypeScript, Closure, Hack, Flow, C#?
–
• Python
–
• Python (mypy)
• ……
– (Any )
• e.g. Blame Calculus ( )
• Python (mypy)
18. • :
• (np.array, chainer.Variable )
⇒
• shape
– shape
•
( : forward backward )
(1)
def __call__(self, x : np.array) -> np.array:
19. • shape Array(m,n,o)
……
– reshape
⇒ (c.f. )
– Haskell hmatrix API †
……
•
(2)
† https://hackage.haskell.org/package/hmatrix-0.18.2.0/docs/Numeric-LinearAlgebra-Static.html
25. •
( 1 540 2.1GB )
parsy-1.1.0 290m7.032s
pyparsing-2.2.0 562m41.623s
funcparserlib-0.3.6 79m45.315s
megaparsec-5.3.1 (Haskell) 18m12.025s
attoparsec-0.13.1.0 (Haskell) 15m46.415s
: Python str Haskell
ByteString(bytes )