FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python_reference/numpy_matrix.py at master · wavelets/python_reference · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
wavelets
/
python_reference
Public
forked from
rasbt/python_reference
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
python_reference
/
numpy_matrix.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (23 loc) · 1 KB
Breadcrumbs
python_reference
/
numpy_matrix.py
Copy path
File metadata and controls
36 lines (23 loc) · 1 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
# numpy matrix operations
# sr 12/01/2013
import
numpy
ary1
=
numpy
.
array
([
1
,
2
,
3
,
4
,
5
])
# must be same type
ary2
=
numpy
.
zeros
((
3
,
4
))
# 3x4 matrix consisiting of 0s
ary3
=
numpy
.
ones
((
3
,
4
))
# 3x4 matrix consisiting of 1s
ary4
=
numpy
.
identity
(
3
)
# 3x3 identity matrix
ary5
=
ary1
.
copy
()
# make a copy of ary1
item1
=
ary3
[
0
,
0
]
# item in row1, column1
ary2
.
shape
# tuple of dimensions. Here: (3,4)
ary2
.
size
# number of elements. Here: 12
ary2_t
=
ary2
.
transpose
()
# transposes matrix
ary2
.
ravel
()
# makes an array linear (1-dimensional)
# by concatenating rows
ary2
.
reshape
(
2
,
6
)
# reshapes array (must have same dimensions)
ary3
[
0
:
2
,
0
:
3
]
# submatrix of first 2 rows and first 3 columns
ary3
=
ary3
[[
2
,
0
,
1
]]
# re-arrange rows
# element-wise operations
ary1
+
ary1
ary1
*
ary1
numpy
.
dot
(
ary1
,
ary1
)
# matrix/vector (dot) product
numpy
.
sum
(
ary1
)
# sums up all elements in the array
numpy
.
mean
(
ary1
)
# average of all elements in the array
Back
|
FazBrowse Home
|
New Git URL