File: t_Sample_large.py

package info (click to toggle)
openturns 1.24-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,204 kB
  • sloc: cpp: 256,662; python: 63,381; ansic: 4,414; javascript: 406; sh: 180; xml: 164; yacc: 123; makefile: 98; lex: 55
file content (61 lines) | stat: -rwxr-xr-x 1,361 bytes parent folder | download | duplicates (2)
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
#! /usr/bin/env python

import openturns as ot

ot.TESTPREAMBLE()

# We create an empty Sample
sample = ot.Sample(0, 2)
sample.setName("EmptySample")
print("sample=", repr(sample))

try:
    # We access the element of the sample
    p = sample[0]
    print("p=", repr(p))

    # We should NEVER go here
    raise
except Exception:
    pass

# We create an small Sample
sample = ot.Sample(1, 2)
sample.setName("SmallSample")
print("sample=", repr(sample))
print(sample)
print(sample._repr_html_())

# We access the element of the sample
p = ot.Point(sample[0])
print("p=", repr(p))
try:
    # We try to access past the last element of the point
    p0, p1, p2 = p[0], p[1], p[2]
    print("p[0]=", p0, " p[1]=", p1, " p[2]=", p2)
    # We should NEVER go here
    raise
except Exception:
    pass

# We create a big Sample
sample = ot.Sample(1000000, 2)
sample.setName("BigSample")

# We populate the sample
for i in range(sample.getSize()):
    sample[i, 0] = i
    sample[i, 1] = i

print("sample first point=", repr(sample[0]))
print("sample last  point=", repr(sample[sample.getSize() - 1]))

# Test pretty-print or a sample with relatively large dimension
size = 49
dimension = 50
sample = ot.Sample(size, dimension)
sample.setName("BigSample50x50")
for i in range(size):
    sample[i] = ot.Point(list(range(dimension))) / size

print(sample._repr_html_())