Skip to content

Commit

Permalink
Merge pull request apachecn#452 from cclauss/patch-1
Browse files Browse the repository at this point in the history
谢谢老哥 | Define reduce() in Python 3
  • Loading branch information
jiangzhonglian authored Sep 30, 2018
2 parents 8926e94 + 448d7b0 commit 07b94e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/py2.x/dl/fc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import numpy as np
from activators import SigmoidActivator, IdentityActivator

try:
reduce # Python 2
except NameError: # Python 3
from functools import reduce


# 全连接层实现类
class FullConnectedLayer(object):
Expand Down Expand Up @@ -224,4 +229,4 @@ def gradient_check():
labels, data_set = transpose(train_data_set())
net = Network([8, 3, 8])
net.gradient_check(data_set[0], labels[0])
return net
return net
8 changes: 6 additions & 2 deletions src/py2.x/dl/rnn.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-


from __future__ import print_function
import numpy as np
from cnn import element_wise_op
from activators import ReluActivator, IdentityActivator

try:
reduce # Python 2
except NameError: # Python 3
from functools import reduce


class RecurrentLayer(object):
'''
Expand Down Expand Up @@ -154,4 +158,4 @@ def test():
l.forward(x[0])
l.forward(x[1])
l.backward(d, ReluActivator())
return l
return l

0 comments on commit 07b94e4

Please sign in to comment.