File: numpy_ex.py

package info (click to toggle)
python-pylatex 1.4.2%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,044 kB
  • sloc: python: 3,810; sh: 209; makefile: 169; xml: 12
file content (44 lines) | stat: -rwxr-xr-x 1,053 bytes parent folder | download
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
#!/usr/bin/env python3
"""
This example shows numpy functionality.

..  :copyright: (c) 2014 by Jelte Fennema.
    :license: MIT, see License for more details.
"""

# begin-doc-include
import numpy as np

from pylatex import Document, Math, Matrix, Section, Subsection, VectorName

if __name__ == "__main__":
    a = np.array([[100, 10, 20]]).T

    doc = Document()
    section = Section("Numpy tests")
    subsection = Subsection("Array")

    vec = Matrix(a)
    vec_name = VectorName("a")
    math = Math(data=[vec_name, "=", vec])

    subsection.append(math)
    section.append(subsection)

    subsection = Subsection("Matrix")
    M = np.matrix([[2, 3, 4], [0, 0, 1], [0, 0, 2]])
    matrix = Matrix(M, mtype="b")
    math = Math(data=["M=", matrix])

    subsection.append(math)
    section.append(subsection)

    subsection = Subsection("Product")

    math = Math(data=["M", vec_name, "=", Matrix(M * a)])
    subsection.append(math)

    section.append(subsection)

    doc.append(section)
    doc.generate_pdf("numpy_ex", clean_tex=False)