Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python_one_week_4_biologists_solutions
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hub-courses
python_one_week_4_biologists_solutions
Commits
911e2ccf
Unverified
Commit
911e2ccf
authored
4 years ago
by
Bertrand NÉRON
Browse files
Options
Downloads
Patches
Plain Diff
fix doc in matrix
parent
dba0c7b4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
source/_static/code/matrix.py
+22
-9
22 additions, 9 deletions
source/_static/code/matrix.py
with
22 additions
and
9 deletions
source/_static/code/matrix.py
+
22
−
9
View file @
911e2ccf
...
...
@@ -91,18 +91,14 @@ def to_str(matrix):
# by design all matrix cols have same size
for
row
in
zip
(
*
matrix
):
cells
=
[
str
(
cell
)
for
cell
in
row
]
s
+=
"
"
.
join
(
cells
)
+
"
\n
"
s
+=
"
\t
"
.
join
(
cells
)
+
"
\n
"
return
s
def
mult
(
matrix
,
val
):
"""
:param matrix: the matrix
to compute the size
:param matrix: the matrix
:type matrix: matrix
:param rows_no: the number of rows
:type rows_no: int
:param col_no: the number of columns
:type col_no: int
:param val: the value to mult the matrix with
:type val: int
:return: a new matrix corresponding the scalar product of matrix * val
...
...
@@ -115,6 +111,21 @@ def mult(matrix, val):
return
new_matrix
def
mult_inplace
(
matrix
,
val
):
"""
compute the scalar product of a matrix and a value
do this operation in place
:param matrix: the matrix
:type matrix: matrix
:param val: the value to mult the matrix with
:type val: int
"""
for
col
in
matrix
:
for
row_nb
,
cell
in
enumerate
(
col
):
col
[
row_nb
]
=
cell
*
val
def
get_row
(
matrix
,
row_no
):
"""
:param matrix: the matrix to compute the size
...
...
@@ -221,8 +232,7 @@ def replace_row(matrix, row_no, row):
for
col_no
,
value
in
enumerate
(
row
):
set_cell
(
matrix
,
row_no
,
col_no
,
value
)
if
__name__
==
'
__main__
'
:
m
=
create
(
5
,
3
)
print
(
m
)
...
...
@@ -233,4 +243,7 @@ if __name__ == '__main__':
print
(
to_str
(
m
))
print
(
"
get row 0
"
,
get_row
(
m
,
0
))
print
(
"
get col 0
"
,
get_col
(
m
,
0
))
m2
=
create
(
3
,
2
,
4
)
mult_inplace
(
m2
,
2
)
print
(
to_str
(
m2
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment