0

i want to print a vector (148K length) in python (Jupyter). but only 8-10 characters of it showed. like this: [0 0 0 ... 0 0 0] i want to see the result fully.

import re
import nltk 
import numpy
import pandas
from nltk.corpus import stopwords
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

vocab=numpy.array(pandas.read_excel('E:\\for_bow.xlsx'))

def word_extraction(sentence):
    ignore = set(stopwords.words('english'))    
    words = re.sub("[^\w]", " ",  sentence).split()   
    cleaned_text = [w.lower() for w in words
                    if w not in ignore]
    return cleaned_text

def generate_bow(allsentences):          
    for sentence in allsentences:        
        words = word_extraction(sentence)        
        bag_vector = numpy.zeros(len(vocab),int)        
        for w in words:            
            for i,word in enumerate(vocab):                
                if word == w:                     
                    bag_vector[i] += 1
        print("{0}\n{1}\n".format(sentence,numpy.array(bag_vector)))


input_text=["text1", "text2", "text3"]
generate_bow(input_text)

i read in another post here that i should use this code:

from IPython.core.interactiveshell import InteractiveShell
    InteractiveShell.ast_node_interactivity = "all"

i tried this, but didn't work.

Mamad_Knight
  • 31
  • 1
  • 6
  • 1
    Why would you want to see 148K items in an array? That will take a lot of resources just to render, and you can't possibly make sense of it from visually scanning such a huge list – roganjosh Feb 17 '20 at 20:19
  • i just want to see the code working. i want to use vector as an input for classifier. what other way you suggest for seeing the result instead of array? – Mamad_Knight Feb 17 '20 at 20:43
  • Dump it to a file? Index it and take the first 100 entries? It's just not practical to have hundreds of thousands of entries dumped into the terminal – roganjosh Feb 17 '20 at 20:47
  • actually worked with this: numpy.set_printoptions(threshold=sys.maxsize) – Mamad_Knight Feb 18 '20 at 18:37

0 Answers0