|
5541 | 5541 |
|
5542 | 5542 | """)) |
5543 | 5543 |
|
| 5544 | +add_newdoc('numpy.core.multiarray', 'dtype', ('metadata', |
| 5545 | + """ |
| 5546 | + Either ``None`` or a readonly dictionary of metadata (mappingproxy). |
| 5547 | +
|
| 5548 | + The metadata field can be set using any dictionary at data-type |
| 5549 | + creation. NumPy currently has no uniform approach to propagating |
| 5550 | + metadata; although some array operations preserve it, there is no |
| 5551 | + guarantee that others will. |
| 5552 | +
|
| 5553 | + .. warning:: |
| 5554 | +
|
| 5555 | + Although used in certain projects, this feature was long undocumented |
| 5556 | + and is not well supported. Some aspects of metadata propagation |
| 5557 | + are expected to change in the future. |
| 5558 | +
|
| 5559 | + Examples |
| 5560 | + -------- |
| 5561 | +
|
| 5562 | + >>> dt = np.dtype(float, metadata={"key": "value"}) |
| 5563 | + >>> dt.metadata["key"] |
| 5564 | + 'value' |
| 5565 | + >>> arr = np.array([1, 2, 3], dtype=dt) |
| 5566 | + >>> arr.dtype.metadata |
| 5567 | + mappingproxy({'key': 'value'}) |
| 5568 | +
|
| 5569 | + Adding arrays with identical datatypes currently preserves the metadata: |
| 5570 | +
|
| 5571 | + >>> (arr + arr).dtype.metadata |
| 5572 | + mappingproxy({'key': 'value'}) |
| 5573 | +
|
| 5574 | + But if the arrays have different dtype metadata, the metadata may be |
| 5575 | + dropped: |
| 5576 | +
|
| 5577 | + >>> dt2 = np.dtype(float, metadata={"key2": "value2"}) |
| 5578 | + >>> arr2 = np.array([3, 2, 1], dtype=dt2) |
| 5579 | + >>> (arr + arr2).dtype.metadata is None |
| 5580 | + True # The metadata field is cleared so None is returned |
| 5581 | + """)) |
| 5582 | + |
5544 | 5583 | add_newdoc('numpy.core.multiarray', 'dtype', ('name', |
5545 | 5584 | """ |
5546 | 5585 | A bit-width name for this data-type. |
|
0 commit comments