Add all the values and add the value at the end

2

I have the following code in Python:

import numpy as np
from math import pi
t = np.linspace(-2*pi,2*pi,16300) #Creo un vector de 16300 puntos de -2*pi a 2*pi
x = np.sinc(t) 
print(x)

I want to algebraically add all the points of x and add that data to the end of a new arrangement.

Therefore, the new arrangement will have 16301 points.

    
asked by Raymundo Torres 25.07.2017 в 20:38
source

1 answer

3

Simply use numpy.sum to do the sum and numpy.append to create a new array with the values of x adding the sum at the end:

y = np.append(x, np.sum(x))

Simple example:

>>> import numpy as np

>>> a = np.array([1, 2, 3, 4])
>>> b = np.append(a, np.sum(a))
>>> b
array([ 1,  2,  3,  4, 10])
    
answered by 25.07.2017 / 21:08
source