Gracias por todos los consejos. Hice esto:
cols = np.loadtxt(args.bram, dtype=str, usecols=[2,8]) x = cols[:,0] y = cols[:,1] max_x = np.argmax(y) y = float(str(y).lstrip("0")) plt.plot(x,y) plt.show() El nuevo error es este: $ python plot_bram.py -b bram_ac_real_test -f 50 Traceback (most recent call last): File "plot_bram.py", line 27, in <module> y = float(str(y).lstrip("0")) ValueError: could not convert string to float: ['0000000000' '0000000000' '0000000000' '00-4834129' '0000000000' '0000000000' '0000000000' '0000000000'] Entiendo que este es el contenido del arreglo "y": ['0000000000' '0000000000' '0000000000' '00-4834129' '0000000000' '0000000000' '0000000000' '0000000000'] Esta representación esta correcta? El 29 de diciembre de 2015, 12:37, Yamila Moreno Suárez <yamila...@gmail.com > escribió: > Rolando, el error te indica que tienes un tipo "ndarray" y que los ndarray > no tienen "lstrip". > > lstrip es un método de strings (cadenas de texto), como la que ves en el > ejemplo que te dio Juanlu. > > Siguiendo con los consejos que te han dado en correos anteriores, lo que > tendrías que hacer es (1)pasar el valor de tu ndarray (que si no me > equivoco es 00-48....) a string, (2)aplicarle la modificación y (3)después > volver a pasarlo al tipo que necesites. > > en varios pasos: > y = str(y) > y = y.lstrip("0") > y = float(y) > > en un solo paso: > y = float(str(y).lstrip("0")) > > suerte :) > > > > 2015-12-29 19:20 GMT+01:00 Rolando Paz <flx...@gmail.com>: > >> Mira lo que surge: >> >> $ python plot_bram.py -b bram_ac_real -f 50 >> Traceback (most recent call last): >> File "plot_bram.py", line 27, in <module> >> y = y.lstrip("0") >> AttributeError: 'numpy.ndarray' object has no attribute 'lstrip' >> >> Codigo: >> >> cols = np.loadtxt(args.bram, dtype=str, usecols=[2,8]) >> >> x = cols[:,0] >> y = cols[:,1] >> >> max_x = np.argmax(y) >> >> y = y.lstrip("0") >> >> plt.plot(x,y) >> plt.show() >> >> >> >> >> El 29 de diciembre de 2015, 12:10, Juan Luis Cano <juanlu...@gmail.com> >> escribió: >> >>> On 2015-12-29 18:20, Rolando Paz wrote: >>> >>> Lo que entiendo que necesito es encontrar una función que elimine todos >>> los ceros a la izquierda del signo menos. >>> >>> >>> Tal vez puedes probar con >>> >>> >>> "00-4834129".lstrip("0") >>> '-4834129' >>> >>> https://docs.python.org/3/library/stdtypes.html#str.lstrip >>> >>> Juan Luis >>> >>> _______________________________________________ >>> Python-es mailing list >>> Python-es@python.org >>> https://mail.python.org/mailman/listinfo/python-es >>> FAQ: http://python-es-faq.wikidot.com/ >>> >>> >> >> _______________________________________________ >> Python-es mailing list >> Python-es@python.org >> https://mail.python.org/mailman/listinfo/python-es >> FAQ: http://python-es-faq.wikidot.com/ >> >> > > > -- > Yamila Moreno Suárez > http://dendarii.es > http://moduslaborandi.net > > _______________________________________________ > Python-es mailing list > Python-es@python.org > https://mail.python.org/mailman/listinfo/python-es > FAQ: http://python-es-faq.wikidot.com/ > >
bram_ac_real_test
Description: Binary data
#!/usr/bin/env python # -*- coding: utf-8 -*- ''' Script that plots the bram's data obtained from the IBOB. Autor: Rolando Paz Fecha: 29/11/2015 ''' import numpy as np import matplotlib.pyplot as plt import argparse parser = argparse.ArgumentParser(description="Script that plots the bram's data obtained from the IBOB.") parser.add_argument('-b','--bram', help="Name of BRAM that will be processed") parser.add_argument('-f','--fre', help="Test frequency signal in MHz. Example: $python plot_bram.py -b bram_file -f 33 (33MHz)") args = parser.parse_args() freq = args.fre cols = np.loadtxt(args.bram, dtype=str, usecols=[2,8]) x = cols[:,0] y = cols[:,1] max_x = np.argmax(y) y = float(str(y).lstrip("0")) #Regla de 3 para determinar el valor del numero de canales teorico ancho_de_banda_MHz = 100 canales = 1024 test_signal = int(freq) dato_teorico = (test_signal*canales)/ancho_de_banda_MHz plt.rc('font', size=9.2) plt.subplot(1,1,1) plt.plot(x,y) plt.title('Autocorrelation \nTest Frequency Signal= %iMHz, Channels of the Maximum Value= %i, Theoretical Channel Value= %i'%(int(freq),max_x,dato_teorico)) plt.ylabel('Power (arbitrary units)') plt.grid() plt.xlabel('Channels') plt.xlim(0,1024) plt.show()
_______________________________________________ Python-es mailing list Python-es@python.org https://mail.python.org/mailman/listinfo/python-es FAQ: http://python-es-faq.wikidot.com/