Numpy: '

Creado en 8 nov. 2018  ·  4Comentarios  ·  Fuente: numpy/numpy

Estoy bastante seguro de que lo siguiente es un error, pero infórmeme si no lo es. Se agradecería mucho una solución.

Estoy haciendo una codificación estándar en caliente a través de SCKlearn, y obviamente estoy usando Numpy en el proceso. Todo está bien cuando dejo la opción de impresión como predeterminada, pero cuando uso la función numpy.set_printoptions(threshold='nan') para imprimir la totalidad de la matriz de codificación en caliente (en lugar del resumen de Numpy), aparece el error en el título del problema. Aquí está el código y el informe de seguimiento / error correspondiente:

import numpy
from numpy import array
from numpy import argmax
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import OneHotEncoder

data = "+++++++++QVQLVQSGGGVVQPGRSLRLSCAASGFTFSSHRMHWVRQAPGKGLEWVAAVSNDGSNEYYADSVKGRFTISRDKSTSTLYLQMDSLRPEDTAVYYCARERCVSSSCWARALDYWGQGSLVTVCS++++++++++"
seq_string = list(data)
print(seq_string)
values = array(seq_string)
print(values)
label_encoder = LabelEncoder()
integer_encoded = label_encoder.fit_transform(values)
print(integer_encoded)
onehot_encoder = OneHotEncoder(sparse=False)
integer_encoded = integer_encoded.reshape(len(integer_encoded), 1)
onehot_encoded = onehot_encoder.fit_transform(integer_encoded)
numpy.set_printoptions(threshold='nan')
print(onehot_encoded)
inverted = label_encoder.inverse_transform([argmax(onehot_encoded[1, :])])
print(inverted)
> ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-43683b44d2e3> in <module>()
     24 onehot_encoded = onehot_encoder.fit_transform(integer_encoded)
     25 numpy.set_printoptions(threshold='nan')
---> 26 print(onehot_encoded)
     27 # invert first example
     28 inverted = label_encoder.inverse_transform([argmax(onehot_encoded[1, :])])

/d/harpy1/s/python/v3-5.1.0/lib/python3.6/site-packages/numpy/core/arrayprint.py in array_str(a, max_line_width, precision, suppress_small)
   1400         return str(a[()])
   1401 
-> 1402     return array2string(a, max_line_width, precision, suppress_small, ' ', "")
   1403 
   1404 def set_string_function(f, repr=True):

/d/harpy1/s/python/v3-5.1.0/lib/python3.6/site-packages/numpy/core/arrayprint.py in array2string(a, max_line_width, precision, suppress_small, separator, prefix, style, formatter, threshold, edgeitems, sign, floatmode, suffix, **kwarg)
    620         return "[]"
    621 
--> 622     return _array2string(a, options, separator, prefix)
    623 
    624 

/d/harpy1/s/python/v3-5.1.0/lib/python3.6/site-packages/numpy/core/arrayprint.py in wrapper(self, *args, **kwargs)
    420             repr_running.add(key)
    421             try:
--> 422                 return f(self, *args, **kwargs)
    423             finally:
    424                 repr_running.discard(key)

/d/harpy1/s/python/v3-5.1.0/lib/python3.6/site-packages/numpy/core/arrayprint.py in _array2string(a, options, separator, prefix)
    435     data = asarray(a)
    436 
--> 437     if a.size > options['threshold']:
    438         summary_insert = "..."
    439         data = _leading_trailing(data, options['edgeitems'])

TypeError: '>' not supported between instances of 'int' and 'str'

Comentario más útil

Pruebe threshold=sys.maxsize lugar, threshold se documenta como int .

Todos 4 comentarios

Pruebe threshold=sys.maxsize lugar, threshold se documenta como int .

¿Quizás deberíamos comenzar a lanzar una excepción en 1.16 cuando la gente pasa la cadena "nan", para prepararlos para Python 3?

Desafortunadamente, stackoverflow recomienda pasar 'nan'.

Pruebe threshold=sys.maxsize lugar, threshold se documenta como int .

¡Gracias! eso funcionó perfectamente bien.
De hecho, el problema surgió siguiendo el enlace SO mencionado.

¿Fue útil esta página
0 / 5 - 0 calificaciones

Temas relacionados

manuels picture manuels  ·  3Comentarios

Foadsf picture Foadsf  ·  3Comentarios

inducer picture inducer  ·  3Comentarios

dmvianna picture dmvianna  ·  4Comentarios

Levstyle picture Levstyle  ·  3Comentarios