Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit581313c

Browse files
committed
merge
2 parentsf9e9ebc +ba6c1d5 commit581313c

File tree

28 files changed

+3655
-78
lines changed

28 files changed

+3655
-78
lines changed

‎README.md‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Linear Regression
1111

1212
Random Forests
1313

14+
Neural Networks
15+
1416
Deep Reinforcement Learning
1517

1618
Support Vector Machine
@@ -39,10 +41,6 @@ Anomaly Detection
3941

4042
Bayesian Networks
4143

42-
Neural Networks
43-
4444
Probabilistic Programming (Sparse Data)
4545

4646
Probabilistic Graphical Models
47-
48-
AGI

‎data.json‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎data/bank_data.csv‎

Lines changed: 3211 additions & 0 deletions
Large diffs are not rendered by default.

‎python_algorithms/.DS_Store‎

0 Bytes
Binary file not shown.

‎python_algorithms/collections/arrays/array.py‎renamed to ‎python_algorithms/collections/arrays/arrays.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
# One extremely notable aspect of NumPy is the manner in which it extends
1919
# Python’s list indexing functionality—especially with multidimensional arrays.
20-
# To illustrate, make a simple two-dimensional array and try some experiments:
20+
# To illustrate, make a simple two-dimensional array and try some experiments:\
2121
a=np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])
2222
print(a)
2323
#=> array([[ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9, 10, 11, 12]])
@@ -49,8 +49,8 @@
4949
#=> array([[ 1, 2, 3, 4],
5050

5151
# python array
52-
#import array as arr
53-
#a = arr.array("I",[1,2,3])
52+
importarrayasarr
53+
a=arr.array("I",[1,2,3])
5454

5555
# Type codeC TypePython TypeMinimum size in bytes
5656
# 'b'signed charint1

‎python_algorithms/collections/collections.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,15 @@
77
# counter
88
# ChainMap
99
# deque
10+
11+
# sequence types:
12+
# tuple, list, string, range
13+
14+
# unpacking sequences
15+
p='ray',0x30,'python'
16+
17+
# no:
18+
name=p[0]
19+
hex=p[1]
20+
# yes:
21+
name,hex=p

‎python_algorithms/collections/dictionaries/combine_dict.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,23 @@
88
print(c['y'])
99
# Outputs 2 (from b)
1010
print(c['z'])
11+
12+
13+
# by hand based on rules
14+
fromitertoolsimportgroupby
15+
mylist= [
16+
{'id':1,'name':'ray' },
17+
{'id':1,'email':'ray@hotmail.com' },
18+
{'id':2,'name':'liz' },
19+
{'id':2,'email':'liz@hotmail.com' }
20+
]
21+
22+
fromfunctoolsimportreduce
23+
# map name, email to id
24+
res= [dict(
25+
reduce(lambday,z:y|z,# entries union
26+
map(lambdax:x.items(),v)# x is a grouper items object generator
27+
)
28+
)fork,vingroupby(mylist,key=lambdax:x['id']) ]
29+
30+
print(res)

‎python_algorithms/collections/dictionaries/dict.py‎

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,67 @@
1-
# to convert a list of tuples to a dictionary using the first value as the key.
2-
# Looked like this (making a database of comic book files):
1+
# Construct a dictionary from pairs
2+
3+
# izip returns iterables
4+
# xrange is better than range
5+
# Loop over dict keys and values
6+
7+
d= {'a':1,'b':2}
8+
# creates many items in mem
9+
fork,vind.items():
10+
print(k,v)
11+
12+
# better in space
13+
fork,vind.iteritems():
14+
print(k,v)
15+
16+
names= []
17+
colors= []
18+
fromitertoolsimportizip
19+
# faster than zip
20+
d=dict(izip(names,colors))
21+
# izip_longest fills in None's for shorter collection
22+
23+
res=zip('abcd','wxyz')
24+
print(dict(res))
25+
26+
print(dict([(k*3,v)fork,vinres]))
27+
28+
# counting with dicts
29+
# ok:
30+
d= {}
31+
forcolorincolors:
32+
ifcolornotind:
33+
d[color]=0
34+
d[color]+=1
35+
36+
# best:
37+
forcolorincolors:
38+
d[color]=d.get(color,0)+1
39+
40+
# grouping with dicts
41+
# ok:
42+
names= ['fred','jim']
43+
d= {}
44+
fornameinnames:
45+
key=len(name)
46+
ifkeynotind:
47+
d[key]= []
48+
d[key].append(name)
49+
50+
# better:
51+
d= {}
52+
fornameinnames:
53+
key=len(name)
54+
d.setdefault(key, []).append(name)
55+
56+
# most best:
57+
d=defaultdict(list)
58+
fornameinnames:
59+
key=len(name)
60+
d[key].append(name)
361

462

63+
# to convert a list of tuples to a dictionary using the first value as the key.
64+
# Looked like this (making a database of comic book files):
565
data= [((31), ("Amazing Spider-Man"), (481), ("Marvel")),
666
((28), ("The Incredible Hulk"), (612), ("Marvel"))]# etc, hundreds more like this.
767

‎python_algorithms/collections/lists/list.py‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
frompprintimportpprint
2-
importitertools
32

43
data= ['OCN',50,91.1, (2012,12,21) ]
54
name,shares,price,date=data
@@ -38,11 +37,3 @@
3837

3938
list.reverse(list_num)
4039
print(list_num)
41-
42-
# flattening
43-
a_list= [[1,2], [3,4], [5,6]]
44-
print(list(itertools.chain.from_iterable(a_list)))
45-
# Output: [1, 2, 3, 4, 5, 6]
46-
# or
47-
print(list(itertools.chain(*a_list)))
48-
# Output: [1, 2, 3, 4, 5, 6]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp