57 from daal.data_management
import (
58 DictionaryIface, HomogenNumericTable, RowMergedNumericTable, BlockDescriptor, convertToHomogen, readWrite, readOnly
61 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
62 if utils_folder
not in sys.path:
63 sys.path.insert(0, utils_folder)
64 from utils
import printArray, printNumericTable
66 if __name__ ==
"__main__":
68 print(
"Row merged numeric table example\n")
78 data1 = np.array([(0.0, 0.1, 0.2, 0.3, 0.4,),
79 (1.0, 1.1, 1.2, 1.3, 1.4,),
80 (2.0, 2.1, 2.2, 2.3, 2.4,),
81 (3.0, 3.1, 3.2, 3.3, 3.4,),
82 (4.0, 4.1, 4.2, 4.3, 4.4,),])
84 data2 = np.array([(0.5, 0.6, 0.7, 0.8, 0.9,),
85 (1.5, 1.6, 1.7, 1.8, 1.9,),
86 (2.5, 2.6, 2.7, 2.8, 2.9,),
87 (3.5, 3.6, 3.7, 3.8, 3.9,),
88 (4.5, 4.6, 4.7, 4.8, 4.9,),
89 (5.5, 5.6, 5.7, 5.8, 5.9,),])
92 table1 = HomogenNumericTable(DictionaryIface.equal, data1)
93 table2 = HomogenNumericTable(DictionaryIface.equal, data2)
95 dataTable = RowMergedNumericTable()
96 dataTable.addNumericTable(table1)
97 dataTable.addNumericTable(table2)
99 block = BlockDescriptor()
102 dataTable.getBlockOfRows(0, nObservations1 + nObservations2, readWrite, block)
103 printArray(block.getArray(), nFeatures, block.getNumberOfRows(), block.getNumberOfColumns(),
104 "Print rows from row merged numeric table as float:")
107 row = block.getArray()
108 for i
in range(nObservations1 + nObservations2):
109 row[i][featureIdx] *= row[i][featureIdx]
110 dataTable.releaseBlockOfRows(block)
112 dataTable.getBlockOfRows(0, nObservations1 + nObservations2, readOnly, block)
113 printArray(block.getArray(), nFeatures, block.getNumberOfRows(), block.getNumberOfColumns(),
114 "Print rows from row merged numeric table as float:")
115 dataTable.releaseBlockOfRows(block)
117 finalizedTable = convertToHomogen(dataTable)
119 printNumericTable(finalizedTable,
"Row merged table converted to homogen numeric table")