50 from daal.data_management
import data_feature_utils, AOSNumericTable, BlockDescriptor, readOnly, readWrite
52 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
53 if utils_folder
not in sys.path:
54 sys.path.insert(0, utils_folder)
55 from utils
import printArray
58 if __name__ ==
"__main__":
60 print(
"Array of structures (AOS) numeric table example\n")
62 points = np.array([(0.5, -1.3, 1, 100.1),
63 (2.5, -3.3, 2, 200.2),
64 (4.5, -5.3, 2, 350.3),
65 (6.5, -7.3, 0, 470.4),
66 (8.5, -9.3, 1, 270.5)],
67 dtype=[(
'x',
'f4'), (
'y',
'f4'), (
'categ',
'i4'), (
'value',
'f8')])
69 nObservations = len(points)
70 nFeatures = len(points[0])
74 dataTable = AOSNumericTable(points)
77 dict = dataTable.getDictionary()
80 dict[0].featureType = data_feature_utils.DAAL_CONTINUOUS
81 dict[1].featureType = data_feature_utils.DAAL_CONTINUOUS
82 dict[2].featureType = data_feature_utils.DAAL_CATEGORICAL
83 dict[3].featureType = data_feature_utils.DAAL_CONTINUOUS
86 dict[2].categoryNumber = 3
90 doubleBlock = BlockDescriptor()
91 dataTable.getBlockOfRows(firstReadRow, nObservations, readWrite, doubleBlock)
93 doubleBlock.getArray(), nFeatures, doubleBlock.getNumberOfRows(),
94 doubleBlock.getNumberOfColumns(),
"Print AOS data structures as double:" 96 dataTable.releaseBlockOfRows(doubleBlock)
101 intBlock = BlockDescriptor(ntype=np.intc)
102 dataTable.getBlockOfColumnValues(readFeatureIdx, firstReadRow, nObservations, readOnly, intBlock)
104 intBlock.getArray(), 1, intBlock.getNumberOfRows(), intBlock.getNumberOfColumns(),
105 "Print the third feature of AOS:", flt64=
False 107 dataTable.releaseBlockOfColumnValues(intBlock)