Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hub-courses
python_one_week_4_biologists_solutions
Commits
0b208e19
Verified
Commit
0b208e19
authored
Mar 11, 2019
by
Bertrand NÉRON
Browse files
fix python2 syntax
parent
71760b40
Changes
1
Hide whitespace changes
Inline
Side-by-side
source/_static/code/matrix.py
View file @
0b208e19
...
...
@@ -3,7 +3,7 @@ Implementation of simple matrix
"""
def
create
(
row_num
,
col_num
,
val
=
None
):
def
create
(
row_num
,
col_num
,
val
=
None
):
"""
:param row_num: the number of rows
:type row_num: int
...
...
@@ -177,8 +177,7 @@ def set_col(matrix, col_no, val):
:type val: any
"""
_check_index
(
matrix
,
0
,
col_no
)
row_max
,
col_max
=
size
(
matrix
)
for
row_n
in
range
(
im
):
for
row_n
in
range
(
matrix
):
set_cell
(
matrix
,
row_n
,
col_no
,
val
)
...
...
@@ -216,8 +215,8 @@ def replace_row(matrix, row_no, row):
row_max
,
col_max
=
size
(
matrix
)
if
len
(
row
)
!=
row_max
:
raise
RuntimeError
(
"the size of row {0} does not fit to matrix size {1}x{2}"
.
format
(
len
(
row
),
row_max
,
col_max
))
row_max
,
col_max
))
_check_index
(
matrix
,
row_no
,
0
)
for
col_no
,
value
in
enumerate
(
row
):
set_cell
(
matrix
,
row_no
,
col_no
,
value
)
...
...
@@ -226,12 +225,12 @@ def replace_row(matrix, row_no, row):
if
__name__
==
'__main__'
:
m
=
create
(
5
,
3
)
print
m
set_cell
(
m
,
0
,
0
,
1
)
set_cell
(
m
,
0
,
2
,
2
)
set_cell
(
m
,
4
,
0
,
12
)
set_cell
(
m
,
4
,
2
,
15
)
print
to_str
(
m
)
print
"get row 0"
,
get_row
(
m
,
0
)
print
"get col 0"
,
get_col
(
m
,
0
)
print
(
m
)
set_cell
(
m
,
0
,
0
,
1
)
set_cell
(
m
,
0
,
2
,
2
)
set_cell
(
m
,
4
,
0
,
12
)
set_cell
(
m
,
4
,
2
,
15
)
print
(
to_str
(
m
)
)
print
(
"get row 0"
,
get_row
(
m
,
0
)
)
print
(
"get col 0"
,
get_col
(
m
,
0
)
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment