Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
nam
ProxPython
Commits
a835964a
Commit
a835964a
authored
Sep 02, 2019
by
constantin.hoeing
Browse files
Upload New File
parent
2daa6f41
Changes
1
Hide whitespace changes
Inline
Side-by-side
proxtoolbox/Utilities/RANDsrc.py
0 → 100644
View file @
a835964a
""" RANDsrc.py
written on September 2. 2019 by
Constantin Höing
Inst. Fuer Numerische und Angewandte Mathematik
Universität Göttingen
Description: < Description >
Input: m,n: shape of return numpy array
alphabet: array of two values
state: propability for values in alphabet
Output: random numpy array of shape m,n
Usage: randMatrix = RANDsrc(m ,n ,alphabet=[1,-1], state=[0.5, 0.5] )
!!!!!!!!!!!!!!!!!!! has no error handling !!!!!!!!!!!!!!!
"""
from
numpy
import
full
,
ndenumerate
from
numpy.random
import
rand
def
RANDsrc
(
m
,
n
,
alphabet
=
[
1
,
-
1
],
state
=
[
0.5
,
0.5
]):
#res = full((m, n), alphabet[0])
res
=
rand
(
m
,
n
)
check1
=
state
[
0
]
#check2 = state[1]
for
idx
,
val
in
ndenumerate
(
res
):
if
val
<
check1
:
res
[
idx
]
=
alphabet
[
0
]
elif
val
>=
check1
:
res
[
idx
]
=
alphabet
[
1
]
#print(res)
return
res
if
__name__
==
"__main__"
:
RANDsrc
(
2
,
3
,
[
3
,
4
],
[
0
,
1
])
\ No newline at end of file
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