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

datastructures_aos.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_aos.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_AOS"></a>
17 ## @example datastructures_aos.py
18 
19 import os
20 import sys
21 
22 import numpy as np
23 
24 from daal.data_management import features, AOSNumericTable, BlockDescriptor, readOnly, readWrite
25 
26 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
27 if utils_folder not in sys.path:
28  sys.path.insert(0, utils_folder)
29 from utils import printArray
30 
31 
32 if __name__ == "__main__":
33 
34  print("Array of structures (AOS) numeric table example\n")
35 
36  points = np.array([(0.5, -1.3, 1, 100.1),
37  (2.5, -3.3, 2, 200.2),
38  (4.5, -5.3, 2, 350.3),
39  (6.5, -7.3, 0, 470.4),
40  (8.5, -9.3, 1, 270.5)],
41  dtype=[('x','f4'), ('y','f4'), ('categ','i4'), ('value','f8')])
42 
43  nObservations = len(points)
44  nFeatures = len(points[0])
45 
46  # Construct AOS numericTable for a data array with nFeatures fields and nObservations elements
47  # Dictionary will be initialized with type information from ndarray
48  dataTable = AOSNumericTable(points)
49 
50  # Get the dictionary and update it with additional information about data
51  dict = dataTable.getDictionary()
52 
53  # Add a feature type to the dictionary
54  dict[0].featureType = features.DAAL_CONTINUOUS
55  dict[1].featureType = features.DAAL_CONTINUOUS
56  dict[2].featureType = features.DAAL_CATEGORICAL
57  dict[3].featureType = features.DAAL_CONTINUOUS
58 
59  # Set the number of categories for a categorical feature
60  dict[2].categoryNumber = 3
61 
62  # Read a block of rows
63  firstReadRow = 0
64  doubleBlock = BlockDescriptor()
65  dataTable.getBlockOfRows(firstReadRow, nObservations, readWrite, doubleBlock)
66  printArray(
67  doubleBlock.getArray(), nFeatures, doubleBlock.getNumberOfRows(),
68  doubleBlock.getNumberOfColumns(),"Print AOS data structures as double:"
69  )
70  dataTable.releaseBlockOfRows(doubleBlock)
71 
72  # Read a feature (column)
73  readFeatureIdx = 2
74 
75  intBlock = BlockDescriptor(ntype=np.intc)
76  dataTable.getBlockOfColumnValues(readFeatureIdx, firstReadRow, nObservations, readOnly, intBlock)
77  printArray(
78  intBlock.getArray(), 1, intBlock.getNumberOfRows(), intBlock.getNumberOfColumns(),
79  "Print the third feature of AOS:", flt64=False
80  )
81  dataTable.releaseBlockOfColumnValues(intBlock)

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