Quantcast

numpy equivalent functionality

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

numpy equivalent functionality

Andrei Berceanu
Hi guys,

I have 2 short numpy-related questions.

In numpy, if one can invert an arbitrary array arr along a given axis using the syntax

    arr[::-1,...]

What is the equivalent idiom in Julia?

The other issue is, how can I truncate an array between a lower and upper bound?
In numpy, this is easily done with np.clip:

    http://docs.scipy.org/doc/numpy/reference/generated/numpy.clip.html

Tnx!
A

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: numpy equivalent functionality

Jacob Quinn
Check out `clamp` for your second question: http://docs.julialang.org/en/latest/stdlib/base/#Base.clamp


On Wed, Jul 23, 2014 at 10:07 AM, Andrei Berceanu <[hidden email]> wrote:
Hi guys,

I have 2 short numpy-related questions.

In numpy, if one can invert an arbitrary array arr along a given axis using the syntax

    arr[::-1,...]

What is the equivalent idiom in Julia?

The other issue is, how can I truncate an array between a lower and upper bound?
In numpy, this is easily done with np.clip:

    http://docs.scipy.org/doc/numpy/reference/generated/numpy.clip.html

Tnx!
A


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: numpy equivalent functionality

Matt Bauman
In reply to this post by Andrei Berceanu
On Wednesday, July 23, 2014 10:07:20 AM UTC-4, Andrei Berceanu wrote:
In numpy, if one can invert an arbitrary array arr along a given axis using the syntax

    arr[::-1,...]

And with regards to this, I think you're after `flipdim` — http://docs.julialang.org/en/latest/stdlib/base/#Base.flipdim

There's also the Matlab-like names flipud and fliplr for the first two axes (up/down and left/right).
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: numpy equivalent functionality

Tim Holy
In reply to this post by Andrei Berceanu
A[end:-1:1, ...]

On Wednesday, July 23, 2014 07:07:20 AM Andrei Berceanu wrote:

> Hi guys,
>
> I have 2 short numpy-related questions.
>
> In numpy, if one can invert an arbitrary array *arr* along a given axis
> using the syntax
>
>     *arr[::-1,...]*
>
> What is the equivalent idiom in Julia?
>
> The other issue is, how can I truncate an array between a lower and upper
> bound?
> In numpy, this is easily done with np.clip:
>
>     http://docs.scipy.org/doc/numpy/reference/generated/numpy.clip.html
>
> Tnx!
> A

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: numpy equivalent functionality

Andrei Berceanu
Thanks guys, works like a charm!
A

On Wednesday, July 23, 2014 4:32:56 PM UTC+2, Tim Holy wrote:
A[end:-1:1, ...]

On Wednesday, July 23, 2014 07:07:20 AM Andrei Berceanu wrote:

> Hi guys,
>
> I have 2 short numpy-related questions.
>
> In numpy, if one can invert an arbitrary array *arr* along a given axis
> using the syntax
>
>     *arr[::-1,...]*
>
> What is the equivalent idiom in Julia?
>
> The other issue is, how can I truncate an array between a lower and upper
> bound?
> In numpy, this is easily done with np.clip:
>
>     <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.clip.html" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fdocs.scipy.org%2Fdoc%2Fnumpy%2Freference%2Fgenerated%2Fnumpy.clip.html\46sa\75D\46sntz\0751\46usg\75AFQjCNFl6eycZ1oHTBUeO-E3VJohS863tg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fdocs.scipy.org%2Fdoc%2Fnumpy%2Freference%2Fgenerated%2Fnumpy.clip.html\46sa\75D\46sntz\0751\46usg\75AFQjCNFl6eycZ1oHTBUeO-E3VJohS863tg';return true;">http://docs.scipy.org/doc/numpy/reference/generated/numpy.clip.html
>
> Tnx!
> A

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: numpy equivalent functionality

Stefan Karpinski
You can also write that range as `end:-1:1` in Julia (similar to Matlab).


On Wed, Jul 23, 2014 at 8:14 AM, Andrei Berceanu <[hidden email]> wrote:
Thanks guys, works like a charm!
A


On Wednesday, July 23, 2014 4:32:56 PM UTC+2, Tim Holy wrote:
A[end:-1:1, ...]

On Wednesday, July 23, 2014 07:07:20 AM Andrei Berceanu wrote:

> Hi guys,
>
> I have 2 short numpy-related questions.
>
> In numpy, if one can invert an arbitrary array *arr* along a given axis
> using the syntax
>
>     *arr[::-1,...]*
>
> What is the equivalent idiom in Julia?
>
> The other issue is, how can I truncate an array between a lower and upper
> bound?
> In numpy, this is easily done with np.clip:
>
>     http://docs.scipy.org/doc/numpy/reference/generated/numpy.clip.html
>
> Tnx!
> A


Loading...