Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> from numpy import *
- >>> import itertools
- >>> array([x for x in itertools.product(arange(2), arange(3))])
- array([[0, 0],
- [0, 1],
- [0, 2],
- [1, 0],
- [1, 1],
- [1, 2]])
- In [14]: a = arange(5)
- In [18]: r = array(meshgrid(a,a))
- In [20]: r.shape
- Out[20]: (2, 5, 5)
- In [21]: r
- Out[21]:
- array([[[0, 1, 2, 3, 4],
- [0, 1, 2, 3, 4],
- [0, 1, 2, 3, 4],
- [0, 1, 2, 3, 4],
- [0, 1, 2, 3, 4]],
- [[0, 0, 0, 0, 0],
- [1, 1, 1, 1, 1],
- [2, 2, 2, 2, 2],
- [3, 3, 3, 3, 3],
- [4, 4, 4, 4, 4]]])
- In [3]: a = arange(5)
- In [4]: a[:,newaxis] * a[newaxis,:]
- Out[4]:
- array([[ 0, 0, 0, 0, 0],
- [ 0, 1, 2, 3, 4],
- [ 0, 2, 4, 6, 8],
- [ 0, 3, 6, 9, 12],
- [ 0, 4, 8, 12, 16]])
- In [6]: a = ones((2,5))
- In [7]: a[:,newaxis] * a[newaxis,:]
- Out[7]:
- array([[[ 1., 1., 1., 1., 1.],
- [ 1., 1., 1., 1., 1.]],
- [[ 1., 1., 1., 1., 1.],
- [ 1., 1., 1., 1., 1.]]])
- In [8]: a.shape
- Out[8]: (2, 5)
- In [9]: b = a[:,newaxis] * a[newaxis,:]
- In [10]: b.shape
- Out[10]: (2, 2, 5)
- xx = numpy.zeros(n) + x.reshape(n,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement