Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
matrice
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
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
Pages Raphael
matrice
Commits
afee7e8b
Commit
afee7e8b
authored
4 years ago
by
rpages
Browse files
Options
Downloads
Patches
Plain Diff
travail
parent
a2351efd
Branches
master
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
matrice.py
+48
-0
48 additions, 0 deletions
matrice.py
matrix.py
+28
-3
28 additions, 3 deletions
matrix.py
with
76 additions
and
3 deletions
matrice.py
0 → 100644
+
48
−
0
View file @
afee7e8b
class
matrice
():
def
__init__
(
self
,
l
,
_format
=
None
):
self
.
liste
=
l
a
=
len
(
l
[
0
])
if
not
_format
:
for
i
in
l
:
if
len
(
i
)
!=
a
:
raise
ValueError
(
'
All lines do not share same length
'
)
self
.
format
=
(
len
(
l
),
a
)
else
:
self
.
format
=
_format
def
__repr__
(
self
):
l
=
self
.
liste
lr
=
[]
for
i
in
l
:
ch
=
'
[
'
for
j
in
i
:
ch
=
ch
+
'
{}
'
.
format
(
j
)
lr
.
append
(
ch
+
'
]
'
)
return
(
'
\n
'
.
join
(
lr
))
def
__add__
(
self
,
other
):
if
not
isinstance
(
other
,
matrice
):
raise
TypeError
(
"
other(={}) n
'
est pas une matrice
"
)
l1
=
self
.
liste
l2
=
other
.
liste
if
not
self
.
format
==
other
.
format
:
raise
ValueError
(
'
matrices do not share the same format
'
)
n
,
m
=
self
.
format
l
=
[[
l1
[
i
][
j
]
+
l2
[
i
][
j
]
for
j
in
range
(
m
)]
for
i
in
range
(
n
)]
return
(
matrice
(
l
,(
n
,
m
)))
def
__mul__
(
self
,
other
):
if
not
isinstance
(
other
,
matrice
):
raise
TypeError
(
"
other(={}) n
'
est pas une matrice
"
)
l1
=
self
.
liste
l2
=
other
.
liste
if
not
self
.
format
[
1
]
==
other
.
format
[
0
]:
raise
ValueError
(
"
matrices are not of formats compatible for matrice multiplication
"
)
n
,
k
=
self
.
format
k1
,
m
=
other
.
format
l
=
[[
sum
(
l1
[
i
][
l
]
*
l2
[
l
][
j
]
for
l
in
range
(
k
))
for
j
in
range
(
m
)]
for
i
in
range
(
n
)]
return
(
matrice
(
l
,(
n
,
m
)))
This diff is collapsed.
Click to expand it.
matrix.py
+
28
−
3
View file @
afee7e8b
...
...
@@ -6,13 +6,38 @@ class Matrice:
self
.
_nrows
=
nrows
def
__repr__
(
self
):
raise
NotImplementedError
l
=
self
.
liste
lr
=
[]
for
i
in
l
:
ch
=
'
[
'
for
j
in
i
:
ch
=
ch
+
'
{}
'
.
format
(
j
)
lr
.
append
(
ch
+
'
]
'
)
return
(
'
\n
'
.
join
(
lr
))
def
__add__
(
self
,
other
):
raise
NotImplementedError
if
not
isinstance
(
other
,
matrice
):
raise
TypeError
(
"
other(={}) n
'
est pas une matrice
"
)
l1
=
self
.
liste
l2
=
other
.
liste
if
not
self
.
format
==
other
.
format
:
raise
ValueError
(
'
matrices do not share the same format
'
)
n
,
m
=
self
.
_nrows
,
self
.
_ncols
l
=
[[
l1
[
i
][
j
]
+
l2
[
i
][
j
]
for
j
in
range
(
m
)]
for
i
in
range
(
n
)]
return
(
matrice
(
m
,
n
,
l
))
def
__mul__
(
self
,
other
):
raise
NotImplementedError
if
not
isinstance
(
other
,
matrice
):
raise
TypeError
(
"
other(={}) n
'
est pas une matrice
"
)
l1
=
self
.
liste
l2
=
other
.
liste
if
not
self
.
_ncols
==
other
.
_nrows
:
raise
ValueError
(
"
matrices are not of formats compatible for matrice multiplication
"
)
n
,
k
=
self
.
_nrows
,
self
.
_ncols
k1
,
m
=
other
.
_nrows
,
other
.
_ncols
l
=
[[
sum
(
l1
[
i
][
l
]
*
l2
[
l
][
j
]
for
l
in
range
(
k
))
for
j
in
range
(
m
)]
for
i
in
range
(
n
)]
return
(
matrice
(
m
,
n
,
l
))
def
nombre_de_colonnes
(
self
,
other
):
raise
NotImplementedError
...
...
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