Skip to content

Instantly share code, notes, and snippets.

@astrofrog
Created March 19, 2019 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astrofrog/e92af1483bbc776dd6db4e461a750285 to your computer and use it in GitHub Desktop.
Save astrofrog/e92af1483bbc776dd6db4e461a750285 to your computer and use it in GitHub Desktop.
In [1]: import numpy as np
In [2]: x = np.arange(1000000)
In [3]: y = x[::2]
In [4]: y.__array_interface__
Out[4]:
{'data': (4658720768, False),
'strides': (16,),
'descr': [('', '<i8')],
'typestr': '<i8',
'shape': (500000,),
'version': 3}
In [5]: z = np.array([1,2,3])
In [7]: a = np.broadcast_to(z, (10000, 3))
In [8]: a
Out[8]:
array([[1, 2, 3],
[1, 2, 3],
[1, 2, 3],
...,
[1, 2, 3],
[1, 2, 3],
[1, 2, 3]])
In [9]: a.__array_interface__
Out[9]:
{'data': (140273029586960, True),
'strides': (0, 8),
'descr': [('', '<i8')],
'typestr': '<i8',
'shape': (10000, 3),
'version': 3}
In [11]: b = np.broadcast_to(3, (3, 4, 5))
In [12]: b.__array_interface__
Out[12]:
{'data': (140272993648288, True),
'strides': (0, 0, 0),
'descr': [('', '<i8')],
'typestr': '<i8',
'shape': (3, 4, 5),
'version': 3}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment