forked from lazyprogrammer/machine_learning_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan1.py
34 lines (25 loc) · 732 Bytes
/
scan1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# https://deeplearningcourses.com/c/unsupervised-machine-learning-hidden-markov-models-in-python
# https://udemy.com/unsupervised-machine-learning-hidden-markov-models-in-python
# http://lazyprogrammer.me
# theano scan example: calculate x^2
from __future__ import print_function, division
from builtins import range
# Note: you may need to update your version of future
# sudo pip install -U future
import numpy as np
import theano
import theano.tensor as T
x = T.vector('x')
def square(x):
return x*x
outputs, updates = theano.scan(
fn=square,
sequences=x,
n_steps=x.shape[0],
)
square_op = theano.function(
inputs=[x],
outputs=[outputs],
)
o_val = square_op(np.array([1, 2, 3, 4, 5]))
print("output:", o_val)