|
2771 | 2771 | >>> y.shape = (3, 6)
|
2772 | 2772 | Traceback (most recent call last):
|
2773 | 2773 | File "<stdin>", line 1, in <module>
|
2774 |
| - ValueError: total size of new array must be unchanged |
| 2774 | + ValueError: cannot reshape array of size 24 into shape (3,6) |
2775 | 2775 | >>> np.zeros((4,2))[::2].shape = (-1,)
|
2776 | 2776 | Traceback (most recent call last):
|
2777 | 2777 | File "<stdin>", line 1, in <module>
|
|
2854 | 2854 | Examples
|
2855 | 2855 | --------
|
2856 | 2856 | >>> import numpy as np
|
2857 |
| - >>> y = np.reshape(np.arange(2*3*4), (2,3,4)) |
| 2857 | + >>> y = np.reshape(np.arange(2 * 3 * 4, dtype=np.int32), (2, 3, 4)) |
2858 | 2858 | >>> y
|
2859 | 2859 | array([[[ 0, 1, 2, 3],
|
2860 | 2860 | [ 4, 5, 6, 7],
|
2861 | 2861 | [ 8, 9, 10, 11]],
|
2862 | 2862 | [[12, 13, 14, 15],
|
2863 | 2863 | [16, 17, 18, 19],
|
2864 |
| - [20, 21, 22, 23]]]) |
| 2864 | + [20, 21, 22, 23]]], dtype=np.int32) |
2865 | 2865 | >>> y.strides
|
2866 | 2866 | (48, 16, 4)
|
2867 |
| - >>> y[1,1,1] |
2868 |
| - 17 |
2869 |
| - >>> offset=sum(y.strides * np.array((1,1,1))) |
2870 |
| - >>> offset/y.itemsize |
2871 |
| - 17 |
2872 |
| -
|
2873 |
| - >>> x = np.reshape(np.arange(5*6*7*8), (5,6,7,8)).transpose(2,3,1,0) |
| 2867 | + >>> y[1, 1, 1] |
| 2868 | + np.int32(17) |
| 2869 | + >>> offset = sum(y.strides * np.array((1, 1, 1))) |
| 2870 | + >>> offset // y.itemsize |
| 2871 | + np.int64(17) |
| 2872 | +
|
| 2873 | + >>> x = np.reshape(np.arange(5*6*7*8, dtype=np.int32), (5, 6, 7, 8)) |
| 2874 | + >>> x = x.transpose(2, 3, 1, 0) |
2874 | 2875 | >>> x.strides
|
2875 | 2876 | (32, 4, 224, 1344)
|
2876 |
| - >>> i = np.array([3,5,2,2]) |
| 2877 | + >>> i = np.array([3, 5, 2, 2], dtype=np.int32) |
2877 | 2878 | >>> offset = sum(i * x.strides)
|
2878 |
| - >>> x[3,5,2,2] |
2879 |
| - 813 |
2880 |
| - >>> offset / x.itemsize |
2881 |
| - 813 |
| 2879 | + >>> x[3, 5, 2, 2] |
| 2880 | + np.int32(813) |
| 2881 | + >>> offset // x.itemsize |
| 2882 | + np.int64(813) |
2882 | 2883 |
|
2883 | 2884 | """))
|
2884 | 2885 |
|
|
4964 | 4965 | 0
|
4965 | 4966 | >>> np.multiply.identity
|
4966 | 4967 | 1
|
4967 |
| - >>> np.power.identity |
4968 |
| - 1 |
| 4968 | + >>> print(np.power.identity) |
| 4969 | + None |
4969 | 4970 | >>> print(np.exp.identity)
|
4970 | 4971 | None
|
4971 | 4972 | """))
|
|
5053 | 5054 | --------
|
5054 | 5055 | >>> import numpy as np
|
5055 | 5056 | >>> np.add.ntypes
|
5056 |
| - 18 |
| 5057 | + 22 |
5057 | 5058 | >>> np.multiply.ntypes
|
5058 |
| - 18 |
| 5059 | + 23 |
5059 | 5060 | >>> np.power.ntypes
|
5060 |
| - 17 |
| 5061 | + 21 |
5061 | 5062 | >>> np.exp.ntypes
|
5062 |
| - 7 |
| 5063 | + 10 |
5063 | 5064 | >>> np.remainder.ntypes
|
5064 |
| - 14 |
| 5065 | + 16 |
5065 | 5066 |
|
5066 | 5067 | """))
|
5067 | 5068 |
|
|
5080 | 5081 | --------
|
5081 | 5082 | >>> import numpy as np
|
5082 | 5083 | >>> np.add.types
|
5083 |
| - ['??->?', 'bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', |
5084 |
| - 'LL->L', 'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'FF->F', 'DD->D', |
5085 |
| - 'GG->G', 'OO->O'] |
5086 |
| -
|
5087 |
| - >>> np.multiply.types |
5088 |
| - ['??->?', 'bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', |
5089 |
| - 'LL->L', 'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'FF->F', 'DD->D', |
5090 |
| - 'GG->G', 'OO->O'] |
| 5084 | + ['??->?', 'bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', ... |
5091 | 5085 |
|
5092 | 5086 | >>> np.power.types
|
5093 |
| - ['bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', 'LL->L', |
5094 |
| - 'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'FF->F', 'DD->D', 'GG->G', |
5095 |
| - 'OO->O'] |
| 5087 | + ['bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', ... |
5096 | 5088 |
|
5097 | 5089 | >>> np.exp.types
|
5098 |
| - ['f->f', 'd->d', 'g->g', 'F->F', 'D->D', 'G->G', 'O->O'] |
| 5090 | + ['e->e', 'f->f', 'd->d', 'f->f', 'd->d', 'g->g', 'F->F', 'D->D', 'G->G', 'O->O'] |
5099 | 5091 |
|
5100 | 5092 | >>> np.remainder.types
|
5101 |
| - ['bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', 'LL->L', |
5102 |
| - 'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'OO->O'] |
| 5093 | + ['bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', ... |
5103 | 5094 |
|
5104 | 5095 | """))
|
5105 | 5096 |
|
|
5953 | 5944 | >>> import numpy as np
|
5954 | 5945 | >>> dt = np.dtype([('name', np.str_, 16), ('grades', np.float64, (2,))])
|
5955 | 5946 | >>> print(dt.fields)
|
5956 |
| - {'grades': (dtype(('float64',(2,))), 16), 'name': (dtype('|S16'), 0)} |
| 5947 | + {'name': (dtype('|S16'), 0), 'grades': (dtype(('float64',(2,))), 16)} |
5957 | 5948 |
|
5958 | 5949 | """))
|
5959 | 5950 |
|
|
6131 | 6122 | >>> (arr + arr).dtype.metadata
|
6132 | 6123 | mappingproxy({'key': 'value'})
|
6133 | 6124 |
|
6134 |
| - But if the arrays have different dtype metadata, the metadata may be |
6135 |
| - dropped: |
| 6125 | + If the arrays have different dtype metadata, the first one wins: |
6136 | 6126 |
|
6137 | 6127 | >>> dt2 = np.dtype(float, metadata={"key2": "value2"})
|
6138 | 6128 | >>> arr2 = np.array([3, 2, 1], dtype=dt2)
|
6139 |
| - >>> (arr + arr2).dtype.metadata is None |
6140 |
| - True # The metadata field is cleared so None is returned |
| 6129 | + >>> print((arr + arr2).dtype.metadata) |
| 6130 | + {'key': 'value'} |
6141 | 6131 | """))
|
6142 | 6132 |
|
6143 | 6133 | add_newdoc('numpy._core.multiarray', 'dtype', ('name',
|
|
0 commit comments