473,395 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to get a wrap aound slice of numpy array

Hi, I am learning Numpy and using it for a course project.
Suppose x = [0, 1, 2, 3, 4], I know that x[0:2] would give [0,1], and
x[-1] give [4], is there a way that I can get [4,0,1]. I try x[-1:2],
but it returns an empty array.

I am doing convolution (e.g. convolve [0, 1, 2, 3, 4] with [1,-2,1])
with wrap-around boundary condition, so sometimes the indices would
wrap around the boundaries, and sometimes not. I would like to find a
generic expression for both cases.

Apr 20 '07 #1
2 4085
da********@yahoo.com wrote:
Hi, I am learning Numpy and using it for a course project.
Welcome! You might want to ask more numpy questions on the numpy mailing list.
Answers to numpy questions here tend to be hit-or-miss.

http://www.scipy.org/Mailing_Lists
Suppose x = [0, 1, 2, 3, 4], I know that x[0:2] would give [0,1], and
x[-1] give [4], is there a way that I can get [4,0,1]. I try x[-1:2],
but it returns an empty array.
x[[-1, 0, 1]]

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Apr 20 '07 #2
Thanks. I didn't know numpy can do vector indexing as in Matlab.

Apr 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Alexandre Guimond | last post by:
Hi all, i'm trying to deepcopy a slice object but i get the following error. Does anyone know a workaround? ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on Python 2.4.3 (#69,...
2
by: K. Jansma | last post by:
Hi, given an array: import numpy a = numpy.arange(100).reshape((10,10)) print a
2
by: robert | last post by:
in Gnuplot (Gnuplot.utils) the input array will be converted to a Numeric float array as shown below. When I insert a numpy array into Gnuplot like that below, numbers 7.44 are cast to 7.0 Why is...
2
by: Chris Smith | last post by:
Howdy, I'm a college student and for one of we are writing programs to numerically compute the parameters of antenna arrays. I decided to use Python to code up my programs. Up to now I haven't...
5
by: robert | last post by:
Turning algs for old NumPy modules into numpy code I suffer from this: Upon further processing of returns of numpy calculations, lots of data in an apps object tree will become elementary numpy...
0
by: Gary Herron | last post by:
Marlin Rowley wrote: Numpy can do this for you. First, do you really mean the array to contain lists of one string each? If so: kludge here array(, dtype='|S1') array(, ,
1
by: martin.nordstrom87 | last post by:
Hi! I'm trying to wrap numpy with Cython and I've tried to use this guide to manage this: http://wiki.cython.org/WrappingNumpy However when I send an array to mysum() it gives me the right answer...
2
by: Rick Giuly | last post by:
Hello All, Case 1 This generates an error, which makes sense because the argument should be a list of numbers: numpy.array(10,10) Case 2 This does not generate an error and the result is an...
3
by: Rüdiger Werner | last post by:
Hello! Out of curiosity and to learn a little bit about the numpy package i've tryed to implement a vectorised version of the 'Sieve of Zakiya'. While the code itself works fine it is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.