numpy.dtype.metadata#
attribute
- dtype.metadata#
Either
Noneor a readonly dictionary of metadata (mappingproxy).The metadata field can be set using any dictionary at data-typecreation. NumPy currently has no uniform approach to propagatingmetadata; although some array operations preserve it, there is noguarantee that others will.
Warning
Although used in certain projects, this feature was long undocumentedand is not well supported. Some aspects of metadata propagationare expected to change in the future.
Examples
>>>importnumpyasnp>>>dt=np.dtype(float,metadata={"key":"value"})>>>dt.metadata["key"]'value'>>>arr=np.array([1,2,3],dtype=dt)>>>arr.dtype.metadatamappingproxy({'key': 'value'})
Adding arrays with identical datatypes currently preserves the metadata:
>>>(arr+arr).dtype.metadatamappingproxy({'key': 'value'})
If the arrays have different dtype metadata, the first one wins:
>>>dt2=np.dtype(float,metadata={"key2":"value2"})>>>arr2=np.array([3,2,1],dtype=dt2)>>>print((arr+arr2).dtype.metadata){'key': 'value'}
On this page