FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithms-python/algorithms/matrix/copy_transform.py at master · ivan1911/algorithms-python · GitHub
ivan1911
/
algorithms-python
Public
forked from
keon/algorithms
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithms-python
/
algorithms
/
matrix
/
copy_transform.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
66 lines (56 loc) · 1.67 KB
Breadcrumbs
algorithms-python
/
algorithms
/
matrix
/
copy_transform.py
Copy path
File metadata and controls
66 lines (56 loc) · 1.67 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def
rotate_clockwise
(
matrix
):
new
=
[]
for
row
in
reversed
(
matrix
):
for
i
,
elem
in
enumerate
(
row
):
try
:
new
[
i
].
append
(
elem
)
except
IndexError
:
new
.
insert
(
i
, [])
new
[
i
].
append
(
elem
)
return
new
def
rotate_counterclockwise
(
matrix
):
new
=
[]
for
row
in
matrix
:
for
i
,
elem
in
enumerate
(
reversed
(
row
)):
try
:
new
[
i
].
append
(
elem
)
except
IndexError
:
new
.
insert
(
i
, [])
new
[
i
].
append
(
elem
)
return
new
def
top_left_invert
(
matrix
):
new
=
[]
for
row
in
matrix
:
for
i
,
elem
in
enumerate
(
row
):
try
:
new
[
i
].
append
(
elem
)
except
IndexError
:
new
.
insert
(
i
, [])
new
[
i
].
append
(
elem
)
return
new
def
bottom_left_invert
(
matrix
):
new
=
[]
for
row
in
reversed
(
matrix
):
for
i
,
elem
in
enumerate
(
reversed
(
row
)):
try
:
new
[
i
].
append
(
elem
)
except
IndexError
:
new
.
insert
(
i
, [])
new
[
i
].
append
(
elem
)
return
new
if
__name__
==
'__main__'
:
def
print_matrix
(
matrix
,
name
):
print
(
'{}:
\n
['
.
format
(
name
))
for
row
in
matrix
:
print
(
' {}'
.
format
(
row
))
print
(
']
\n
'
)
matrix
=
[
[
1
,
2
,
3
],
[
4
,
5
,
6
],
[
7
,
8
,
9
],
]
print_matrix
(
matrix
,
'initial'
)
print_matrix
(
rotate_clockwise
(
matrix
),
'clockwise'
)
print_matrix
(
rotate_counterclockwise
(
matrix
),
'counterclockwise'
)
print_matrix
(
top_left_invert
(
matrix
),
'top left invert'
)
print_matrix
(
bottom_left_invert
(
matrix
),
'bottom left invert'
)
Back
|
FazBrowse Home
|
New Git URL