49 from daal.data_management
import data_feature_utils, AOSNumericTable, BlockDescriptor, readOnly, readWrite
51 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
52 if utils_folder
not in sys.path:
53 sys.path.insert(0, utils_folder)
54 from utils
import printArray
57 if __name__ ==
"__main__":
59 print(
"Array of structures (AOS) numeric table example\n")
61 points = np.array([(0.5, -1.3, 1, 100.1),
62 (2.5, -3.3, 2, 200.2),
63 (4.5, -5.3, 2, 350.3),
64 (6.5, -7.3, 0, 470.4),
65 (8.5, -9.3, 1, 270.5)],
66 dtype=[(
'x',
'f4'), (
'y',
'f4'), (
'categ',
'i4'), (
'value',
'f8')])
68 nObservations = len(points)
69 nFeatures = len(points[0])
73 dataTable = AOSNumericTable(points)
76 dict = dataTable.getDictionary()
79 dict[0].featureType = data_feature_utils.DAAL_CONTINUOUS
80 dict[1].featureType = data_feature_utils.DAAL_CONTINUOUS
81 dict[2].featureType = data_feature_utils.DAAL_CATEGORICAL
82 dict[3].featureType = data_feature_utils.DAAL_CONTINUOUS
85 dict[2].categoryNumber = 3
89 doubleBlock = BlockDescriptor()
90 dataTable.getBlockOfRows(firstReadRow, nObservations, readWrite, doubleBlock)
92 doubleBlock.getArray(), nFeatures, doubleBlock.getNumberOfRows(),
93 doubleBlock.getNumberOfColumns(),
"Print AOS data structures as double:"
95 dataTable.releaseBlockOfRows(doubleBlock)
100 intBlock = BlockDescriptor(ntype=np.intc)
101 dataTable.getBlockOfColumnValues(readFeatureIdx, firstReadRow, nObservations, readOnly, intBlock)
103 intBlock.getArray(), 1, intBlock.getNumberOfRows(), intBlock.getNumberOfColumns(),
104 "Print the third feature of AOS:", flt64=
False
106 dataTable.releaseBlockOfColumnValues(intBlock)