Example to write and read files with arrays from disk
The package can write arrays and designs to a custom file format. There is a text based format (specified by oapackage.ATEXT
) and a binary format (specified by oapackage.ABINARY
). See the online documentation for details on the file formats.
[1]:
import oapackage
import tempfile
Create a list of two example arrays.
[2]:
lst = [oapackage.exampleArray(32), oapackage.exampleArray(33)]
print(lst)
[array_link: 18, 4, array_link: 18, 4]
Write the two arrays to a file on disk.
[3]:
filename = tempfile.mktemp(".oa")
_ = oapackage.writearrayfile(filename, lst, oapackage.ATEXT)
Display information about the file written.
[4]:
oapackage.oainfo(filename)
file C:\Users\EENDEB~1\AppData\Local\Temp\tmpxc4dnsl6.oa: 18 rows, 4 columns, 2 arrays, mode text, nbits 0
The arrays can be read from disk again using the command readarrayfile
.
[6]:
lst2 = oapackage.readarrayfile(filename)
print(lst2)
(array_link: 18, 4, array_link: 18, 4)
The first array in the list that was read from disk is:
[7]:
lst2[0].showarray()
array:
0 0 0 0
0 0 0 0
1 1 1 1
1 1 1 1
1 1 -1 -1
1 1 -1 -1
1 -1 1 -1
1 -1 1 -1
1 -1 -1 1
1 -1 -1 1
-1 1 1 -1
-1 1 1 -1
-1 1 -1 1
-1 1 -1 1
-1 -1 1 1
-1 -1 1 1
-1 -1 -1 -1
-1 -1 -1 -1