Questions tagged [genfromtxt]

Numpy function to create arrays from tabular data.

References

287 questions
0
votes
0 answers

How do I read the second column using genfromtxt?

Consider the following data file: ! cat datax 1 1.000 2.000 3.000 3.000 4.000 5.000 6.000 the lines: f=open('datax', 'r') d=np.genfromtxt(f, dtype=None, missing_values=0,usecols=(0)) f.close() succeed but the lines: f=open('datax', 'r')…
wander95
  • 1,298
  • 1
  • 15
  • 22
0
votes
1 answer

numpy.genfromtxt path value

I would like to load a txt file with genformtxt(). the txt file is already in c:. stock=np.genfromtxt('c:\09012017.txt',delimiter=' ',dtype=str,skip_header=1) C:\Anaconda3\lib\site-packages\numpy\lib\npyio.py in genfromtxt(fname, dtype, comments,…
LB10222
  • 3
  • 3
0
votes
1 answer

Error in reading CSV through command line as Numpy 2d Matrix

I am trying to read data in CSV file as numpy matrix using csv.reader() function to store it into Numpy 2d matrix using the following code: import sys import csv filename1 = sys.argv[0] reader = csv.reader(open(filename1, "rb"), delimiter=",") x =…
0
votes
0 answers

genfromtxt issues of import a txt file

I have a data file with top names like: position avgx avgy avgz stdx stdy stdt avgG nemixrms nemiyrms nemirrms rmax 2.800e+00 -4.997e-05 -1.373e-04 2.800e+00 2.812e-03 …
rfeynman
  • 97
  • 1
  • 9
0
votes
1 answer

Read textfile into numpy array

I'm trying to load a textfile into a numpy array. The structure is the following: THE 77534223 AND 30997177 ING 30679488 ENT 17902107 ION 17769261 HER 15277018 FOR 14686159 THA 14222073 NTH 14115952 [...] But I fail using import numpy as np data =…
Suuuehgi
  • 4,547
  • 3
  • 27
  • 32
0
votes
1 answer

ValueError: size of tuple must match number of fields while using genfromtxt

import os import numpy as np os.getcwd() os.chdir('C:/Users/Gururaj/Desktop/tech/python/') data = np.genfromtxt("simple.txt", dtype=None, delimiter=",", names=str(False)) print(data[0]) =========================error as…
0
votes
1 answer

How do I specify dtype str correctly?

File is utility.dat Name D L J H E M RF AF line1 150 4.5 2.0 150 2 Copper 0.8 true line2 140 4.5 2.0 140 2 Aluminium 0.8 true My script is script.py import numpy configName = "utility.dat" lines =…
Dean
  • 65
  • 1
  • 8
0
votes
2 answers

IOError when loading data file to plot

import matplotlib.pyplot as plt import numpy as np x,y = np.genfromtxt('D:\Tanjil\Python\directory\Heat Available Datas.csv',unpack=True , delimiter=',',skip_header=0) plt.plot(x,y,'ro--'), plt.ylabel('Power Input…
0
votes
4 answers

Import data into Python from txt file

I have a .txt file with data arranged as follows: 3430 4735 1 3430 4736 1 3430 4941 2 3430 5072 1 3430 5095 1 3430 5230 1 3430 5299 1 3430 5386 1 3430 5552 1 3430 5555 1 3430 5808 1 3430 5853 1 3430 5896 1 3430 5988 1 3430 6190 4 3430 6191 1 3430…
user8321044
  • 3
  • 1
  • 1
  • 3
0
votes
1 answer

How do I convert a CSV file to an RGB image using python

I'm trying to convert a csv file to an RGB file as follows: from PIL import Image, ImageDraw from numpy import genfromtxt g = open('myFile.csv','r') temp = genfromtxt(g, delimiter = ',') im = Image.fromarray(temp).convert('RGB') pix =…
cookieMonster
  • 75
  • 1
  • 9
0
votes
1 answer

Issues importing datasets (txt file) with Python using numpy library genfromtxt function

I am trying to learn Python, however I am trying to import a dataset and cant get it work correctly... This dataset contains 16 columns and 16 320 rows saved as txt file. I used the genfromtxt function as follow : import numpy as np …
user6473579
0
votes
1 answer

genfromtxt in Python-3.5

I am trying to fix a data set using genfromtxt in Python 3.5. But I keep getting the next error: ndtype = np.dtype(dict(formats=ndtype, names=names)) TypeError: data type not understood This is the code I'm using. Any help will be…
nanny
  • 57
  • 3
  • 9
0
votes
0 answers

Make numpy.genfromtext return comma separated tuples

I am using text = np.sort(np.genfromtxt('new1', delimiter= ' ',dtype=None,usecols=[1,2])) and while printing text, the result I get is space separated values. [(10014024, 'GAM.SW') (10014031, 'GAM.SW') (10014032, 'GAM.SW') (10014032, 'HAM.SW')…
0
votes
1 answer

CSV via NumPy genfromtxt(): dtype for variable string sizes

I'm reading in a CSV using genfromtxt(), and I want all of my values to be strings. I need to specify a string dtype but specifying S results in empty strings: In [83]: s = StringIO("a,b,c\n1,1.3,abcde\n2,4,hihihi") In [84]: data = np.genfromtxt(s,…
0
votes
1 answer

Convert genfromtxt array to regular numpy array

I can't post the data being imported, because it's too much. But, it has both number and string fields and is 5543 rows and 137 columns. I import data with this code (ndnames and ndtypes holds the column names and column datatypes): npArray2 =…
swabygw
  • 813
  • 1
  • 10
  • 22