1

cuando corro mi programa en visual estudio code me saltan varias errores. Sin embargo, cuando lo pruebo en Google Colab, me corre sin ningún problema. Los errores que me aparecen son los siguientes:

$ /bin/python3 /home/ubuntu/prom.py
Traceback (most recent call last):
  File "/home/ubuntu/prom.py", line 5, in <module>
    import matplotlib.pyplot as plt
  File "/usr/local/lib/python3.8/dist-packages/matplotlib/__init__.py", line 109, in <module>
    from . import _api, _version, cbook, docstring, rcsetup
  File "/usr/local/lib/python3.8/dist-packages/matplotlib/rcsetup.py", line 27, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "/usr/local/lib/python3.8/dist-packages/matplotlib/colors.py", line 56, in <module>
    from matplotlib import _api, cbook, scale
  File "/usr/local/lib/python3.8/dist-packages/matplotlib/scale.py", line 19, in <module>
    from numpy import ma
ImportError: cannot import name 'ma' from 'numpy' (/home/ubuntu/numpy.py)

CODIGO PYTHON:

import ctypes
import numpy
import random
import time
import matplotlib.pyplot as plt
import statistics

def mean_py(vector,L):
    S=sum(vector)
    resultado=S/L
    return resultado

if __name__ == '__main__':

    so_file='./promedio.so'
    promedio_c=ctypes.CDLL(so_file)
    promedio_c.mean_c.argtypes=[numpy.ctypeslib.ndpointer(dtype=numpy.float32), ctypes.c_int]
    promedio_c.mean_c.restype=ctypes.c_float

    time_py_total=[]
    time_c_total=[]
    for L in range(1,1000):
        vector =[]
    
        for i in range(0,L):
            n= random.randint(1,30)
            vector.append(n)
        vector_cast= numpy.array(vector, dtype=numpy.float32)
  
    
  
    
        time_py=[]
        for i in range(500):
            start1=time.time()
            Py_resultado=mean_py(vector_cast,L)
            end1=time.time()
            time_py.append((end1-start1)*1000000)
            
        time_py_total.append(statistics.median(time_py))

        #print("El resultado en Python es ",Py_resultado)
        #print((end1-start1)*1000000, " us")
        

        #print(" ")

        time_c=[]
        for j in range(500):
            start2=time.time()
            C_resultado=promedio_c.mean_c(vector_cast,L)
            end2=time.time()
            time_c.append((end2-start2)*1000000)
        time_c_total.append(statistics.median(time_c))

        #print("El resultado en C es ",C_resultado)
        #print((end2-start2)*1000000, " us")

plt.plot(time_py_total,"r")
plt.plot(time_c_total,"b")
plt.legend(["Tiempo Python","Tiempo C"], loc="best")

plt.xlabel("Iteracion")
plt.xlabel("Tiempo de ejecucion en us")
plt.grid()
plt.savefig("promedio_en_python.png",dpi=500)
plt.close

CODIGO EN C:

float mean_c(float *vector, int L){

    float sum=0;
    float resultado =0;

    for(int i=0; i<L;i++){
        
        sum=sum+vector[i];
    }

    resultado=sum/(float)L;
    return resultado;
}

int main(){

    return 0;
}

Yo creo que es un problema con la instalación del numpy y matplotlib. He estado buscando en internet muchas soluciones pero no la encuentro. Agradecería mucho la ayuda.

1 respuesta 1

0

You have named the file the same as the library name. ImportError: cannot import name 'ma' from 'numpy' (/home/ubuntu/numpy.py). Please rename the file /home/ubuntu/numpy.py to something else.

2
  • 1
    Thanks for answering, but the language of the site is Spanish, please translate your answer. ;)
    – Israel-ICM
    el 24 may. 2022 a las 18:30
  • Oh lo siento mucho, Ha nombrado el archivo del mismo modo que el nombre de la biblioteca. ImportError: no se puede importar el nombre 'ma' de 'numpy' (/home/ubuntu/numpy.py). Cambie el nombre del archivo /home/ubuntu/numpy.py por otro.
    – Devil2k4
    el 25 may. 2022 a las 8:50

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.