Python readin .txt and put in an array with numpy

2024/10/15 1:25:08

i want to create an array with numpy. The base is a .txt file which is given in the following form: enter image description here

i tried it with loadtxt:

data = np.loadtxt("myfile.txt",delimiter='\n',skiprows = 1)

The first row with "Zeit" and "Signal" should be skipped i only need the array in this form:

[[0, 1], [0.01, 2], [0.02, 3]]

The Values from "Zeit" and "Signal are seperated with a tab.

i got this error:

ValueError: could not convert string to float: 
Answer

It looks like you shouldn't be passing the delimiter='\n' argument. As I am looking at the loadtxt documentation, this argument seems to specify the delimiter of values on a line, not a delimiter of lines. ...and calling the same function without that argument worked for me.

https://en.xdnf.cn/q/117891.html

Related Q&A

Running a PyQt4 script without a display

I would like to run a Python script that normally opens a Qt window remotely over a connection with no X11 forwarding. Is there any way to create some kind of virtual display that the window drawing ca…

Scrapy : Program organization when interacting with secondary website

Im working with Scrapy 1.1 and I have a project where I have spider 1 scrape site A (where I aquire 90% of the information to fill my items). However depending on the results of the Site A scrape, I ma…

How do I use openpyxl and still maintain OOP structure?

I am using python to do some simulations and using openpyxl to generate the reports. Now the simulation is results are to be divided into several sheets of an excel file. By the principles of OOP my st…

Leaving rows with a giving value in column

UPDATED: In my dataset I have 3 columns (x,y) and VALUE. Its looking like this(sorted already):df1: x , y ,value 1 , 1 , 12 2 , 2 , 12 4 , 3 , 12 1 , 1 , 11 2 , 2 , 11 4 , 3 , 11 1 , 1 , 33 2 , 2 , 33 …

Python Circular dependencies, unable to link variable to other file

I am working on a program that allows me to directly edit a word document through a tkinter application. I am trying to link the tkinter input from my gui file to my main file so that I can execute my …

how to use xlrd module with python for abaqus

Im working on a script for abaqus where I have to import data from an excel file to put them into my script. I already downloaded the xlrd module and it work well on python interpreter (IDLE), but when…

Property in Python with @property.getter

I have an intresting behaviour for the following code:class MyClass:def __init__(self):self.abc = 10@propertydef age(self):return self.abc@age.getterdef age(self):return self.abc + 10@age.setterdef age…

Foreign Key Access

--------------------------------------------MODELS.PY-------------------------------------------- class Artist(models.Model):name = models.CharField("artist", max_length=50) #will display &…

ValueError: could not broadcast input array from shape (22500,3) into shape (1)

I relied on the code mentioned, here, but with minor edits. The version that I have is as follows:import numpy as np import _pickle as cPickle from PIL import Image import sys,ospixels = [] labels = []…

VGG 16/19 Slow Runtimes

When I try to get an output from the pre-trained VGG 16/19 models using Caffe with Python (both 2.7 and 3.5) its taking over 15 seconds on the net.forward() step (on my laptops CPU).I was wondering if …