Questions tagged [genfromtxt]

Numpy function to create arrays from tabular data.

References

287 questions
1
vote
0 answers

Error when Coding Perceptron: ValueError: shapes (124,124) and (1,10) not aligned: 124 (dim 1) != 1 (dim 0)

I'm trying to code a Multi-Layer Perceptron, but it seems I get it wrong when I'm trying to import data from csv file using genfromtxt function from numpy library. from numpy import genfromtxt dfX =…
Augusto.m
  • 11
  • 3
1
vote
1 answer

genfromtxt returning -1 and nan rows

I am trying to read a txt file with numpy and I have the following code import numpy as np def parsefile(filename): return np.genfromtxt(filename, delimiter = dly_delimiter, usecols = dly_usecols, …
Tom
  • 191
  • 1
  • 11
1
vote
0 answers

Extract numbers and text from csv file with Python3.X

I am trying to extract data from a csv file with python 3.6. The data are both numbers and text (it's url addresses): file_name = [-0.47, 39.63, http://example.com] On multiple forums I found this kind of code: data = numpy.genfromtxt(file_name,…
Carlo Bianchi
  • 115
  • 4
  • 15
1
vote
1 answer

Importing txt file with missing values with numpy

I have the following form of a txt file: Notice that some of the fields are completely missing, but the fact that they are missing is important. In the attached image all the measurements are missing due to technical failure but it can happen that…
skrat
  • 648
  • 2
  • 10
  • 27
1
vote
1 answer

Matrix conversion to txt file

I've been studying Machine Learning lately and now I'm working on Factorization Machines (Rendle's first papyer, 2010). I've found later on https://github.com/srendle/libfm so I can apply that for specific train / test data. The matrix (i.e training…
mlx
  • 504
  • 1
  • 4
  • 15
1
vote
1 answer

Issue reading text file with pound sign

I was trying to read a tab-delimited text file like this: 1 2# 3 using: test = genfromtxt('test2.txt', delimiter='\t', dtype = 'string', skip_header=0) However, I get the output only of 1 and 2. The # acts like an ending character in the txt file.…
Alex
  • 1,097
  • 3
  • 11
  • 16
1
vote
1 answer

Read specific columns of .txt file with numy genfromtxt

I try to read a .txt file containing 4 columns with names col1, col2, col3 and col4, with data types string, string, float and float. I just want to read the columns col3 and col4 (for this example). I used: table = numpy.genfromtxt(filename,…
mglasner
  • 75
  • 2
  • 9
1
vote
2 answers

get column names from numpy genfromtxt in python

using numpy genfromtxt in python, i want to be able to get column headers as key for a given data. I tried the following, but not able to get the column names for the corresponding data. column =…
user2406718
  • 263
  • 4
  • 15
1
vote
2 answers

The comments argument of genfromtxt in numpy

I am learning the I/O functions of genfromtxt in numpy. I tried an example from the user guide of numpy. It is about the comments argument of genfromtxt. Here is the example from the user guide of numpy: >>> data = """# ... # Skip me ! ... # Skip me…
TCNO_C
  • 35
  • 7
1
vote
2 answers

Reading file as ndarray in Python

I want to read file as ndarray with variable number of rows and 6 columns and the first row is the names of columns. I used this data = np.genfromtxt('attack-traffic.csv', dtype=float, delimiter=',', names=True) but when I print data.shape It…
1
vote
1 answer

Using np.genfromtxt to read in data that contains arrays

So I am trying to read in some data which looks like this (this is just the first line): 1 14.4132966509 (-1.2936631396696465, 0.0077236319580324952, 0.066687939649724415) (-13.170491147387787, 0.0051387952329040587, 0.0527163312916894) I'm…
Dyell
  • 51
  • 3
1
vote
3 answers

How do I load heterogeneous data (np.genfromtxt) as a 2D array?

I learn from numpy.genfromtxt produces array of what looks like tuples, not a 2D array—why? that numpy.genfromtxt returns a structured ndarray if the data is not homogeneous. How do I load heterogeneous data as a 2D array? For instance, a text file…
SparkAndShine
  • 17,001
  • 22
  • 90
  • 134
1
vote
3 answers

Efficient way to process CSV file into a numpy array

CSV file may not be clean (lines with inconsistent number of elements), unclean lines would need to be disregarded. String manipulation is required during processing. Example input: 20150701 20:00:15.173,0.5019,0.91665 Desired output: float32…
user2180519
1
vote
1 answer

NumPy genfromtxt for different column sizes

I am attempting to extract values from a txt file using numpy.genfromtxt() method. MY txt file looks like this: '! dt tot nsave readext\n', ' 0.002 200 500 F\n', …
Ohm
  • 2,312
  • 4
  • 36
  • 75
1
vote
2 answers

Python - working with uneven columns in rows

I am working with a data with thousands of rows but I have uneven columns as shown below: AB 12 43 54 DM 33 41 45 56 33 77 88 MO 88 55 66 32 34 KL 10 90 87 47 23 48 56 12 First, I want to read the data in…
PyLabour
  • 245
  • 3
  • 5
  • 15