Python* API Reference for Intel® Data Analytics Acceleration Library 2019 Update 4

datastructures_rowmerged.py

Deprecation Notice: With the introduction of daal4py, a package that supersedes PyDAAL, Intel is deprecating PyDAAL and will discontinue support starting with Intel® DAAL 2021 and Intel® Distribution for Python 2021. Until then Intel will continue to provide compatible pyDAAL pip and conda packages for newer releases of Intel DAAL and make it available in open source. However, Intel will not add the new features of Intel DAAL to pyDAAL. Intel recommends developers switch to and use daal4py.

Note: To find daal4py examples, refer to daal4py documentation or browse github repository.

1 # file: datastructures_rowmerged.py
2 #===============================================================================
3 # Copyright 2014-2019 Intel Corporation.
4 #
5 # This software and the related documents are Intel copyrighted materials, and
6 # your use of them is governed by the express license under which they were
7 # provided to you (License). Unless the License provides otherwise, you may not
8 # use, modify, copy, publish, distribute, disclose or transmit this software or
9 # the related documents without Intel's prior written permission.
10 #
11 # This software and the related documents are provided as is, with no express
12 # or implied warranties, other than those that are expressly stated in the
13 # License.
14 #===============================================================================
15 
16 #
17 # ! Content:
18 # ! Python row merged data structures example.
19 # !*****************************************************************************
20 
21 #
22 ## <a name="DAAL-EXAMPLE-PY-DATASTRUCTURES_ROWMERGED"></a>
23 ## \example datastructures_rowmerged.py
24 #
25 
26 import os
27 import sys
28 
29 import numpy as np
30 
31 from daal.data_management import (
32  DictionaryIface, HomogenNumericTable, RowMergedNumericTable, BlockDescriptor, convertToHomogen, readWrite, readOnly
33 )
34 
35 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
36 if utils_folder not in sys.path:
37  sys.path.insert(0, utils_folder)
38 from utils import printArray, printNumericTable
39 
40 if __name__ == "__main__":
41 
42  print("Row merged numeric table example\n")
43 
44  nObservations1 = 5
45  nObservations2 = 6
46  nFeatures = 5
47  firstReadRow = 3
48  nRead = 6
49  featureIdx = 2
50 
51  # Example of using homogeneous numeric table
52  data1 = np.array([(0.0, 0.1, 0.2, 0.3, 0.4,),
53  (1.0, 1.1, 1.2, 1.3, 1.4,),
54  (2.0, 2.1, 2.2, 2.3, 2.4,),
55  (3.0, 3.1, 3.2, 3.3, 3.4,),
56  (4.0, 4.1, 4.2, 4.3, 4.4,),])
57 
58  data2 = np.array([(0.5, 0.6, 0.7, 0.8, 0.9,),
59  (1.5, 1.6, 1.7, 1.8, 1.9,),
60  (2.5, 2.6, 2.7, 2.8, 2.9,),
61  (3.5, 3.6, 3.7, 3.8, 3.9,),
62  (4.5, 4.6, 4.7, 4.8, 4.9,),
63  (5.5, 5.6, 5.7, 5.8, 5.9,),])
64 
65  # Create row merged numeric table consisting of two homogen numeric tables
66  table1 = HomogenNumericTable(DictionaryIface.equal, data1)
67  table2 = HomogenNumericTable(DictionaryIface.equal, data2)
68 
69  dataTable = RowMergedNumericTable()
70  dataTable.addNumericTable(table1)
71  dataTable.addNumericTable(table2)
72 
73  block = BlockDescriptor()
74 
75  # Read one row from merged numeric table
76  dataTable.getBlockOfRows(0, nObservations1 + nObservations2, readWrite, block)
77  printArray(block.getArray(), nFeatures, block.getNumberOfRows(), block.getNumberOfColumns(),
78  "Print rows from row merged numeric table as float:")
79 
80  # Modify row of the merged numeric table
81  row = block.getArray()
82  for i in range(nObservations1 + nObservations2):
83  row[i][featureIdx] *= row[i][featureIdx]
84  dataTable.releaseBlockOfRows(block)
85 
86  dataTable.getBlockOfRows(0, nObservations1 + nObservations2, readOnly, block)
87  printArray(block.getArray(), nFeatures, block.getNumberOfRows(), block.getNumberOfColumns(),
88  "Print rows from row merged numeric table as float:")
89  dataTable.releaseBlockOfRows(block)
90 
91  finalizedTable = convertToHomogen(dataTable)
92 
93  printNumericTable(finalizedTable, "Row merged table converted to homogen numeric table")

For more complete information about compiler optimizations, see our Optimization Notice.