[SciPy-user] mgrid/ogrid...
fred
fredmfp at gmail.com
Tue Jul 24 15:19:49 EDT 2007
Robert Kern a écrit :
> fred wrote:
>
>> Hi all,
>>
>> What's difference between ogrid() and mgrid ?
>>
>
> In [1]: from numpy import *
>
> In [2]: mgrid[0:5,0:5]
> Out[2]:
> array([[[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]],
>
> [[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]]])
>
> In [3]: ogrid[0:5,0:5]
> Out[3]:
> [array([[0],
> [1],
> [2],
> [3],
> [4]]),
> array([[0, 1, 2, 3, 4]])]
>
>
>
Well, I should have try before, and not only read help, sorry.
> mgrid gives you the fully broadcasted arrays. ogrid gives you partial arrays
> which will broadcast against each other. Depending on how you are using them,
> ogrid's results may be more efficient to use because you can often do the bulk
> of your computations on the smaller arrays and only do a handful of operations
> that broadcast against each other to form the final, full result.
>
Thanks for explanation as clear as possible, as usual ;-)
Cheers,
--
http://scipy.org/FredericPetit
More information about the SciPy-User
mailing list