December 2017
Intermediate to advanced
386 pages
10h 42m
English
Up to this point, we only considered arrays that contained native data types, such as floats or integers. If we need an array containing heterogeneous data, we can create an array with arbitrary Python objects as elements, as shown in the following code:
x = np.array([2.5, 'a string', [2,4], {'a':0, 'b':1}])
This will result in an array with the np.object data type, as indicated in the output line reproduced as follows:
array([2.5, 'string', [2, 4], {'a': 0, 'b': 1}], dtype=object)
Read now
Unlock full access