Q:

voltage and current rms calculations python

Im doing som calculations for voltage and current rms values, and just got a new way to do it with more precision. 
It Works well for what it was designed for, full period values, but it doesn´t work for half period values.
spp = 200, and the input is an array with Nx200 values, (period by period).
So i get full 230 V  when i do the full period version, but only get around 100 V from the half period version
full period calculations:
k = np.arange(spp) # 
v_samples = np.vstack((np.zeros(spp), data_u_periods))
#print ("v_samples", v_samples)
v_samples = np.diff(v_samples, axis=0)
#print ("v_samples :", v_samples)

v_cossum = np.cumsum(v_samples * np.cos(2*np.pi/spp*k)) * np.sqrt(2)/spp
v_sinsum = np.cumsum(v_samples * np.sin(2*np.pi/spp*k)) * np.sqrt(2)/spp
print ("fp", 2*np.pi/spp*k)
v_complex = v_cossum + 1j*v_sinsum
v_complex = np.mean(v_complex.reshape((-1,spp)), axis=1)

i_samples = np.vstack((np.zeros(spp), data_i_periods))
i_samples = np.diff(i_samples, axis=0)

i_cossum = np.cumsum(i_samples * np.cos(2*np.pi/spp*k)) * np.sqrt(2)/spp
i_sinsum = np.cumsum(i_samples * np.sin(2*np.pi/spp*k)) * np.sqrt(2)/spp

i_complex = i_cossum + 1j*i_sinsum
i_complex = np.mean(i_complex.reshape((-1,spp)), axis=1)
s_complex = v_complex * i_complex.conjugate() # save for power calculations

ueffs = np.abs(v_complex)
ieffs = np.abs(i_complex)

half period calculations:
data_u_periods = data_u_periods.flatten()
data_i_periods = data_i_periods.flatten()
data_u_periods = data_u_periods.reshape((int(data_u_periods.shape[0]/(int(spp/2))),int(spp/2)))
data_i_periods = data_i_periods.reshape((int(data_i_periods.shape[0]/(int(spp/2))),int(spp/2)))

spp = spp/2
k = np.arange(spp) # 
#print(spp)
#print (k)
#print (data_u_periods.shape)
v_samples = np.vstack((np.zeros(spp), data_u_periods))
#print ("v_samples", v_samples)
v_samples = np.diff(v_samples, axis=0)
#print ("v_samples :", v_samples)
#input("press enter")
v_cossum = np.cumsum(v_samples * np.cos(2*np.pi/spp*k)) * np.sqrt(2)/spp
v_sinsum = np.cumsum(v_samples * np.sin(2*np.pi/spp*k)) * np.sqrt(2)/spp

v_complex = v_cossum + 1j*v_sinsum
v_complex = np.mean(v_complex.reshape((-1,spp)), axis=1)

i_samples = np.vstack((np.zeros(spp), data_i_periods))
i_samples = np.diff(i_samples, axis=0)

i_cossum = np.cumsum(i_samples * np.cos(2*np.pi/spp*k)) * np.sqrt(2)/spp
i_sinsum = np.cumsum(i_samples * np.sin(2*np.pi/spp*k)) * np.sqrt(2)/spp

i_complex = i_cossum + 1j*i_sinsum
i_complex = np.mean(i_complex.reshape((-1,spp)), axis=1)
#s_complex = v_complex * i_complex.conjugate() # save for power calculations
print ("hp", 2*np.pi/spp*k)
ueffs = np.abs(v_complex)
ieffs = np.abs(i_complex)

A:

It was a simple oversight, instead of taking the difference between two periods at the same point, i took the difference between the first and second half of the same period. And the second half vs the first half of the next period....
So now it works as it should!
fixed code: 
"""
    function for getting period RMS values
Args
-----
data_u_periods : all voltage periods
data_i_periods : all current periods
spp : samples per period

Returns
---------
arrays with half period rms values

"""

k = np.arange(spp)  

v_samples = np.vstack((np.zeros(spp), data_u_periods))
v_samples = np.diff(v_samples, axis = 0)

v_prepp_cos = v_samples * np.cos(2*np.pi/spp*k)
v_prepp_sin = v_samples * np.sin(2*np.pi/spp*k)
v_prepp_cos = v_prepp_cos.flatten()
v_prepp_cos = v_prepp_cos.reshape((int(v_prepp_cos.shape[0]/(int(spp/2))), int(spp/2)))
v_prepp_sin = v_prepp_sin.flatten()
v_prepp_sin = v_prepp_sin.reshape((int(v_prepp_sin.shape[0]/(int(spp/2))), int(spp/2)))

#print ("v_samples hp", v_samples)

i_samples = np.vstack((np.zeros(spp), data_i_periods))
i_samples = np.diff(i_samples, axis = 0)

i_prepp_cos = i_samples * np.cos(2*np.pi/spp*k)
i_prepp_sin = i_samples * np.sin(2*np.pi/spp*k)
i_prepp_cos = i_prepp_cos.flatten()
i_prepp_cos = i_prepp_cos.reshape((int(i_prepp_cos.shape[0]/(int(spp/2))), int(spp/2)))
i_prepp_sin = i_prepp_sin.flatten()
i_prepp_sin = i_prepp_sin.reshape((int(i_prepp_sin.shape[0]/(int(spp/2))), int(spp/2)))

spp = spp/2

v_cossum = np.cumsum(v_prepp_cos) * np.sqrt(2)/(2*spp)
v_sinsum = np.cumsum(v_prepp_sin) * np.sqrt(2)/(2*spp)

v_complex = v_cossum + 1j*v_sinsum
v_complex = np.mean(v_complex.reshape((-1, spp)), axis = 1)

i_cossum = np.cumsum(i_prepp_cos) * np.sqrt(2)/(2*spp)
i_sinsum = np.cumsum(i_prepp_sin) * np.sqrt(2)/(2*spp)

i_complex = i_cossum + 1j*i_sinsum
i_complex = np.mean(i_complex.reshape((-1, spp)), axis = 1)
ueffs = np.abs(v_complex)
ieffs = np.abs(i_complex)
#print ("ueff hp", ueffs)

return ueffs, ieffs

