Implementing the 3Blue1Brown description of the Fourier transform in Python + numpy

I have implemented the 3Blue1Brown description of the Fourier transform in Python + numpy for irregular and unclassified data, as described here.

import numpy as np
import matplotlib.pyplot as plt

def polarToRectangular(radii, angles):
    return radii * np.exp(1j * angles)

def frequencyGenerator(time, steps = 100):
    𝛿 = time.max() - time.min()
    M = np.arange(1, steps + 1)(:, np.newaxis)
    return M / 𝛿

def easyFourierTransform(time, values, frequency = None, steps = 100):
    if frequency is None:            
        ft = frequencyGenerator(time, steps)
        frequency = ft.reshape(ft.shape(0))
    else:
        ft = frequency(:, np.newaxis)

    # sorting the inputs
    order = np.argsort(time)
    ts = np.array(time)(order)
    Xs = np.array(values)(order)

    𝜃 = (ts - time.min()) * 2 * np.pi * ft
    Y = polarToRectangular(Xs, 𝜃)(:, :-1) * np.diff(ts)
    amplitude = np.abs(Y.sum(axis=1))
    return frequency, amplitude

I'm thinking maybe I can suggest that this be added to numpy / scypy. However, I am not sure if this small code snippet is qualified to be added upstream. I was wondering if you could help me know:

  • Is this code correct? Does the Fourier transform really return? I want to be sure that there are no logical errors.
  • Is this a performance code or is there any way to improve performance?
  • Is the formatting good enough? Should I comply with the PEP8 standard or numpy / scipy require different best practices?
  • How can I add typing annotations? Especially to make sure the dimensions of the ndarrays are fine.
  • Is this novel or has it been done before? (not necessarily relevant to this forum but it's still my question)

I would appreciate if you could help me with the above points. Thanks in advance.

Keywords: non-uniform, uniform, uneven, sampled, distributed

Django Python increases the value of the database using the model save function

I am looking for a more efficient way to increase the value already saved in the database by the value returned to the model from a form submission.

def save(self, *args, **kwargs):
        l1 = Model.objects.filter(pk=self.pk).values_list('list_1')
        l1n = (l1r(0) for l1r in l1)
        self.list_1 += l1n(0)
        l2 = Model.objects.filter(pk=self.pk).values_list('list_2')
        l2n = (l2r(0) for l2r in l2)
        self.list_2 += l2n(0)
        l3 = Model.objects.filter(pk=self.pk).values_list('list_3')
        l3n = (l3r(0) for l3r in l3)
        self.list_3 += l3n(0)
        super(Model, self).save(*args, **kwargs)

python: how to get the avatar URL of the person who sent the message?

How do you get the avatar URL of the person who sent the command from the context?

@client.command()
async def test(ctx):
    print("Username is = " + ctx.message.author)
    print(ctx.message.author + "'s avatar url is = " )

As you can see, I can easily get the author of the context, but how do I get his avatar image?

I've seen solutions for this, but it's not context

Python – How to create a Bitcoin transaction with Protocoin

How can I create a btc transaction and transmit it with the protocoin library? I want to create a transaction that will be relayed to the node without validating inputs and outputs. Of course, I know that the transaction will not be confirmed. I just want it to be transmitted for a while.
Does anyone know any way I can use to do this? If there are other simpler methods to do this, I would also appreciate it.

Minimal Python P2P application – Software engineering stack exchange

I have a point-to-point application that I want to compile. The part that is new to me is how to establish the network connection (processing the transmitted data is easy). To learn how to build point-to-point applications, could someone give one or more examples of a minimum implementation of a point? point-to-point application that transmits and receives data? The application format in addition to that is simply "in the received data, do this".

Python: import of C ++ files with Min GW

Correct way to import C ++ files using MinGW in python
With sample program.

python – Sound Pattern Recognition

I am working on a school project that involves using Python to detect when a sound clip is played. The clip will be played inside a Windows application at a random time with / or out, and other sounds will be played at the same time.

After hours of online research, I can't seem to find anything that doesn't involve voice recognition.

Some address, or some advice would be very useful.

Thank you.

I haven't tried anything because I can't find anything to try.

python – Exception has occurred: IndexError list index out of range. Enter data in a split

-The type of error is this: Exception has occurred: IndexError
list index out of range on line 43

  • When: When I enter the value 30 in voucher Park = input ("How much time do you want from blue zone, you can pay 30, 60, 90 or 120 minutes") line 40

I've given it several laps and I just didn't find the error, thank you very much in advance.

#El programa te calculara el descuento que obtendrás entregando tu coche, para comprarte uno nuevo.
#Si es de antes del 98 se le aplicará un descuento del 10% si es posterior al 2008 tendrás un descuento de 15%.
#Si es diesel sumale otro 10% y si es gasolina 12%
#El programa debe decirte el descuento final que vas a obtener para comprar tu nuevo coche.
#El programa debe pedir al usuario que marca quiere comprar, el concesionario trabaja con: ford,toyota o wolkswagen.
#El programa debe pedir al usuario si la marca del coche que compra es: electrico,hibrido o gas
#Segun el tipo que sea podra circular en nucleos urbanos con restriccion o no
#Los peajes tambien dependen de  electrico,hibrido o gas
#Impuesto circulación descuento  electrico,hibrido o gas
#Aparcar en zona azul valdra x y a partir de x, depende del tipo, valdra y.
modeloEntrega=input("Introduce la marca, el modelo de coche, el año, si es gasolina o diesel,SEPARADO POR COMASn")
entrada=modeloEntrega.split(',')
marca=str(entrada(0))
modelo=str(entrada(1))
anio=int(entrada(2))
gasolinaDiesel=str(entrada(3))
print (marca,modelo,anio,gasolinaDiesel)

if anio < 1998 and gasolinaDiesel == "diesel" or gasolinaDiesel == "Diesel":
    descuento= 0.10+0.10
    print (descuento)
elif anio > 2008 and gasolinaDiesel == "gasolina" or gasolinaDiesel == "Gasolina":
    descuento= 0.15+0.12
    print (descuento)
else:
    print ("No has introducido valores validos")

modeloCompra=input("Introduce la marca, el modelo, si es electrico, hibrido o gas, SEPARADO POR COMASn")
entrada=modeloCompra.split(',')
marcac=str(entrada(0))
modeloc=str(entrada(1))
tipo=str(entrada(2))
print (marcac,modeloc,tipo)
peajeHora=10

if tipo == "electrico":
    print ("Puede circular en núcleo urbano sin restriccionn")
    #print ("El minuto de zona azul vale 0,10")
    bonoAparcar=input("Cuanto rato quieres de zona azul,puedes pagar 30, 60, 90 o 120 minutos")
    entrada=bonoAparcar.split()
    mediaHora=int(entrada(0))
    unaHora=int(entrada(1))
    horayMedia=int(entrada(2))
    dosHoras=int(entrada(3))
    precioMinuto=10

    if bonoAparcar == 30 :
        bonoAparcar =  10 * 30
        descBono=input(int("Si no has estado los 30 minutos enteros, indica quantos has estado y te haremos el descuento"))
        preciobonoFinal=bonoAparcar - descBono

    elif bonoAparcar == 60:
        bonoAparcar =  10 * 60
        descBono=input(int("Si no has estado los 60 minutos enteros, indica quantos has estado y te haremos el descuento"))
        preciobonoFinal=bonoAparcar - descBono

    elif bonoAparcar == 90:
        bonoAparcar =  10 * 90
        descBono=input(int("Si no has estado los 90 minutos enteros, indica quantos has estado y te haremos el descuento"))
        preciobonoFinal=bonoAparcar - descBono

    elif bonoAparcar == 120:
        bonoAparcar =  10 * 120
        descBono=input(int("Si no has estado los 120 minutos enteros, indica quantos has estado y te haremos el descuento"))
        preciobonoFinal=bonoAparcar - descBono

elif tipo == hibrido:
    print ("Puede circular en núcleo urbano hasta 2 horas al dia")
    bonoAparcar=input("Cuanto rato quieres de zona azul, la fraccion horaria minima es media hora, y el máximo son 2 horas")

elif tipo == gas:
    print ("Puede circular en núcleo urbano hasta 4 horas al dia")
    bonoAparcar=input("Cuanto rato quieres de zona azul, la fraccion horaria minima es media hora, y el máximo son 2 horas")

Eliminating key value of yaml in python

we would like to delete the key and values ​​of a yaml file using python, for example

  - misc_props:
  - attribute: tmp-1
    value: 1
  - attribute: tmp-2
    value: 604800
  - attribute: tmp-3
    value: 100
  - attribute: tmp-4
    value: 1209600
  name: temp_key1
  attr-1: 20
  attr-2: 1
- misc_props:
  - attribute: tmp-1
    value: 1
  - attribute: tmp-2
    value: 604800
  - attribute: tmp-3
    value: 100
  - attribute: tmp-4
    value: 1209600
  name: temp_key2
  atrr-1: 20
  attr-2: 1

From the previous example we would like to delete the entire set of properties and where the name of the key matches the value, for example, if we want to delete the name: temp_key2, the newly created dictionary after deletion will be as follows:

  - misc_props:
  - attribute: tmp-1
    value: 1
  - attribute: tmp-2
    value: 604800
  - attribute: tmp-3
    value: 100
  - attribute: tmp-4
    value: 1209600
  name: temp_key1
  attr-1: 20
  attr-2: 1

python: get the maximum date for a single row value

Hi, I have that data:

              campaign  status  d_cap
date                                 
2019-10-07  campaign_1   start    400
2019-10-13  campaign_2   start    400
2019-10-14  campaign_1  change   1000
2019-10-14  campaign_2  change    800
2019-11-10  campaign_1    stop      0
2019-11-12  campaign_2  change   2000

Required Departure:

              campaign  status  d_cap
date                                 
2019-11-10  campaign_1    stop      0
2019-11-12  campaign_2  change   2000

Therefore, I want to get the latest status and d_cap per single campaign based on the maximum date. I tried to solve this question using for loop, but I think it is not the best solution.