Extending an ndarray

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Extending an ndarray

Søren Nielsen-4
Hi,

I've loaded an image into a ndarray. I'd like to extend the ndarray with a border of zeros all around the ndarray.. does anyone here know how to do this?

Thanks,
Soren
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Extending an ndarray

Alan McIntyre-2
Here's one way (probably not the most efficient or elegant):

# example original array
a=arange(1,26).reshape(5,5)

# place copy of 'a' into upper left corner of a larger array of zeros
b=zeros((10,10))
b[:5,:5]=a


On Wed, May 14, 2008 at 2:48 PM, Søren Nielsen
<[hidden email]> wrote:

> Hi,
>
> I've loaded an image into a ndarray. I'd like to extend the ndarray with a
> border of zeros all around the ndarray.. does anyone here know how to do
> this?
>
> Thanks,
> Soren
> _______________________________________________
> Numpy-discussion mailing list
> [hidden email]
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Extending an ndarray

Søren Nielsen-4
Thanks alan, that works!

Soren

On Wed, May 14, 2008 at 9:02 PM, Alan McIntyre <[hidden email]> wrote:
Here's one way (probably not the most efficient or elegant):

# example original array
a=arange(1,26).reshape(5,5)

# place copy of 'a' into upper left corner of a larger array of zeros
b=zeros((10,10))
b[:5,:5]=a


On Wed, May 14, 2008 at 2:48 PM, Søren Nielsen
<[hidden email]> wrote:
> Hi,
>
> I've loaded an image into a ndarray. I'd like to extend the ndarray with a
> border of zeros all around the ndarray.. does anyone here know how to do
> this?
>
> Thanks,
> Soren
> _______________________________________________
> Numpy-discussion mailing list
> [hidden email]
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion


_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion