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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
"""
>>> import scipy.base as nx
>>> import scipy.base.ufunclike as U
Test fix:
>>> a = nx.array([[1.0, 1.1, 1.5, 1.8], [-1.0, -1.1, -1.5, -1.8]])
>>> U.fix(a)
array([[ 1., 1., 1., 1.],
[ 0., -1., -1., -1.]])
>>> y = nx.zeros(a.shape, float)
>>> U.fix(a, y)
array([[ 1., 1., 1., 1.],
[ 0., -1., -1., -1.]])
>>> y
array([[ 1., 1., 1., 1.],
[ 0., -1., -1., -1.]])
Test isposinf, isneginf, sign
>>> a = nx.array([nx.Inf, -nx.Inf, nx.NaN, 0.0, 3.0, -3.0])
>>> U.isposinf(a)
array([True, False, False, False, False, False], dtype=bool)
>>> U.isneginf(a)
array([False, True, False, False, False, False], dtype=bool)
>>> U.sign(a)
array([ 1, -1, 0, 0, 1, -1])
Same thing with an output array:
>>> y = nx.zeros(a.shape, bool)
>>> U.isposinf(a, y)
array([True, False, False, False, False, False], dtype=bool)
>>> y
array([True, False, False, False, False, False], dtype=bool)
>>> U.isneginf(a, y)
array([False, True, False, False, False, False], dtype=bool)
>>> y
array([False, True, False, False, False, False], dtype=bool)
>>> U.sign(a, y)
array([True, True, False, False, True, True], dtype=bool)
>>> y
array([True, True, False, False, True, True], dtype=bool)
Now log2:
>>> a = nx.array([4.5, 2.3, 6.5])
>>> U.log2(a)
array([ 2.169925 , 1.20163386, 2.70043972])
>>> 2**_
array([ 4.5, 2.3, 6.5])
>>> y = nx.zeros(a.shape, float)
>>> U.log2(a, y)
array([ 2.169925 , 1.20163386, 2.70043972])
>>> y
array([ 2.169925 , 1.20163386, 2.70043972])
"""
from scipy.testing import *
import doctest
def test_suite(level=1):
return doctest.DocTestSuite()
if __name__ == "__main__":
ScipyTest().run()
|