[Python-es] numpy.absolute

Rolando Paz flxpaz en gmail.com
Mar Dic 29 13:47:55 EST 2015


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.ms en 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 <flxpaz en 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 <juanlu001 en 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 en python.org
>>> https://mail.python.org/mailman/listinfo/python-es
>>> FAQ: http://python-es-faq.wikidot.com/
>>>
>>>
>>
>> _______________________________________________
>> Python-es mailing list
>> Python-es en 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 en python.org
> https://mail.python.org/mailman/listinfo/python-es
> FAQ: http://python-es-faq.wikidot.com/
>
>
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://mail.python.org/pipermail/python-es/attachments/20151229/a41bdb15/attachment.html>
------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: bram_ac_real_test
Type: application/octet-stream
Size: 640 bytes
Desc: no disponible
URL: <http://mail.python.org/pipermail/python-es/attachments/20151229/a41bdb15/attachment.obj>
------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: plot_bram.py
Type: text/x-python
Size: 1222 bytes
Desc: no disponible
URL: <http://mail.python.org/pipermail/python-es/attachments/20151229/a41bdb15/attachment.py>


Más información sobre la lista de distribución Python-es