Tag: NUMPY-NDARRAY
He visto muchas formas diferentes de aplicar las reglas del “juego de la vida” en Python. Soy nuevo y estoy tratando de usar numpy y funciones, como se muestra a continuación. Probé la función “cal_live” por sí misma con elementos individuales en el arreglo y la suma se calcula correctamente. . . . Read more
Convertí mi matriz de numpy en un dataframe, sin embargo, el error aún persiste. deseanolized_df = pd.DataFrame(deseanolized) df_ma = deseanolized_df.values.rolling(3, center=True, closed=’both’).mean() df_ma.plot() Salida: “` AttributeError Traceback (most recent call last) /tmp/ipykernel_40/956302484.py in 1 deseanolized_df = pd.DataFrame(deseanolized) —-> 2 df_ma = deseanolized_df.values.rolling(3, center=True, closed=’both’).mean() 3 df_ma.plot() AttributeError: El objeto ‘numpy.ndarray’ . . . Read more
¿Cómo puedo inicializar un ndarray al usar pydantic? Este código genera un ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all(). from pydantic.dataclasses import dataclass import numpy as np @dataclass class TestNumpyArray: numpyArray: np.ndarray = np.zeros(10) testNumpyArray = TestNumpyArray()
Me gustaría transformar una matriz numpy nd con descripciones de dimensiones en un dataframe de pandas. Las siguientes soluciones funcionan, pero parecen un poco lentas para 360000 filas (1.5s en mi máquina, sus resultados pueden variar). import pandas as pd import numpy as np from itertools import product import time . . . Read more
Tengo un array de 4 dimensiones llamado new_arr. Dada una lista de índices, quiero actualizar new_arr basándome en un array antiguo que tengo almacenado, old_arr. Estoy usando un bucle for para hacer esto, pero es ineficiente. Mi código se parece a esto: update_indices = [(2,33,1,8), (4,9,49,50), …] # como ejemplo . . . Read more