Q:

Write a NumPy program to split a given text into lines and split the single line into array values

0

Write a NumPy program to split a given text into lines and split the single line into array values.

Sample text:
01 V Debby Pramod
02 V Artemiy Ellie
03 V Baptist Kamal
04 V Lavanya Davide
05 V Fulton Antwan
06 V Euanthe Sandeep
07 V Endzela Sanda
08 V Victoire Waman
09 V Briar Nur
10 V Rose Lykos

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np 
student = """01	V	Debby Pramod
02	V	Artemiy Ellie
03	V	Baptist Kamal
04	V	Lavanya Davide
05	V	Fulton Antwan
06	V	Euanthe Sandeep
07	V	Endzela Sanda
08	V	Victoire Waman
09	V	Briar Nur
10	V	Rose Lykos"""

print("Original text:") 
print(student)
text_lines = student.splitlines()
text_lines = [r.split('\t') for r in text_lines]
result = np.array(text_lines, dtype=np.str)
print("\nArray from the said text:")
print(result)

Sample Output:

Original text:
01	V	Debby Pramod
02	V	Artemiy Ellie
03	V	Baptist Kamal
04	V	Lavanya Davide
05	V	Fulton Antwan
06	V	Euanthe Sandeep
07	V	Endzela Sanda
08	V	Victoire Waman
09	V	Briar Nur
10	V	Rose Lykos

Array from the said text:
[['01' 'V' 'Debby Pramod']
 ['02' 'V' 'Artemiy Ellie']
 ['03' 'V' 'Baptist Kamal']
 ['04' 'V' 'Lavanya Davide']
 ['05' 'V' 'Fulton Antwan']
 ['06' 'V' 'Euanthe Sandeep']
 ['07' 'V' 'Endzela Sanda']
 ['08' 'V' 'Victoire Waman']
 ['09' 'V' 'Briar Nur']
 ['10' 'V' 'Rose Lykos']]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now