[Numpy-discussion] basic numpy array operation

Robert Kern robert.kern@gmail....
Mon Mar 15 13:22:38 CDT 2010


On Mon, Mar 15, 2010 at 13:20, gerardo.berbeglia <gberbeglia@gmail.com> wrote:
>
> Suppose i have an array A of length n
> I want a variable b to be an array consisting of the first k elements of A
> and variable c to be an array with the last n-k elements of A.
>
> How do you do this?
>
> Example A = np.array([1,2,3,4,5,6]), k = 2
> b = [1,2]
> c=[3,4,5,6]

b = A[:2]
c = A[2:]

-- 
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


More information about the NumPy-Discussion mailing list