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

datastructures_merged.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_merged.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 ## <a name="DAAL-EXAMPLE-PY-DATASTRUCTURES_MERGED"></a>
17 ## \example datastructures_merged.py
18 
19 import os
20 import sys
21 
22 import numpy as np
23 
24 from daal.data_management import (
25  HomogenNumericTable, MergedNumericTable, BlockDescriptor, readWrite, readOnly
26 )
27 
28 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
29 if utils_folder not in sys.path:
30  sys.path.insert(0, utils_folder)
31 from utils import printArray
32 
33 
34 if __name__ == "__main__":
35 
36  print("Merged numeric table example\n")
37 
38  nFeatures1 = 5
39  nFeatures2 = 6
40  firstReadRow = 3
41  nRead = 1
42 
43  # Example of using homogeneous numeric table
44  data1 = np.array([
45  (0.0, 0.1, 0.2, 0.3, 0.4),
46  (1.0, 1.1, 1.2, 1.3, 1.4),
47  (2.0, 2.1, 2.2, 2.3, 2.4),
48  (3.0, 3.1, 3.2, 3.3, 3.4),
49  (4.0, 4.1, 4.2, 4.3, 4.4),
50  ])
51 
52  data2 = np.array([
53  (0.5, 0.6, 0.7, 0.8, 0.9, 1),
54  (1.5, 1.6, 1.7, 1.8, 1.9, 2),
55  (2.5, 2.6, 2.7, 2.8, 2.9, 3),
56  (3.5, 3.6, 3.7, 3.8, 3.9, 4),
57  (4.5, 4.6, 4.7, 4.8, 4.9, 5),
58  ])
59 
60  # Create two homogen numeric tables from data arrays
61  dataTable1 = HomogenNumericTable(data1)
62  dataTable2 = HomogenNumericTable(data2)
63 
64  # Create merged numeric table consisting of two homogen numeric tables
65  dataTable = MergedNumericTable()
66  dataTable.addNumericTable(dataTable1)
67  dataTable.addNumericTable(dataTable2)
68 
69  block = BlockDescriptor()
70 
71  # Read one row from merged numeric table
72  dataTable.getBlockOfRows(firstReadRow, nRead, readWrite, block)
73  printArray(
74  block.getArray(), nFeatures1 + nFeatures2, block.getNumberOfRows(),
75  block.getNumberOfColumns(), "Print 1 row from merged numeric table as double:"
76  )
77 
78  # Modify row of the merged numeric table
79  row = block.getArray()
80  for i in range(nFeatures1 + nFeatures2):
81  row[0][i] *= row[0][i]
82  dataTable.releaseBlockOfRows(block)
83 
84  # Read the same row from homogen numeric tables
85  dataTable1.getBlockOfRows(firstReadRow, nRead, readOnly, block)
86  printArray(
87  block.getArray(), nFeatures1, block.getNumberOfRows(),
88  block.getNumberOfColumns(), "Print 1 row from first homogen numeric table as double:"
89  )
90  dataTable1.releaseBlockOfRows(block)
91 
92  dataTable2.getBlockOfRows(firstReadRow, nRead, readOnly, block)
93  printArray(
94  block.getArray(), nFeatures2, block.getNumberOfRows(),
95  block.getNumberOfColumns(), "Print 1 row from second homogen numeric table as double:"
96  )
97  dataTable2.releaseBlockOfRows(block)

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