Python Forum
Numpy Structure and Efficiency
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Numpy Structure and Efficiency
#2
One advantage of posting to a forum is that you then relax; nothing you can do until someone answers.

It is at those moments your brain actually works!

I solved the issue simply by defining data as an empty 2D array. Then I populated it with another Numpy array.

# Reads in data from STELCOR file
def readData(datafile):
	
	data = np.empty((0, 8), float)
	
	file = open(datafile)

	for line in file:
		if (line[1:6] == "hydro") or (line[1:6] == "HYDRO"):
			time      = convert(line[21:35])
			delta_t	  = convert(line[36:50])
			mass      = convert(line[51:65])
			radius    = convert(line[66:80])
			lum_core  = convert(line[81:95])
			lum_tot   = convert(line[96:110])
			flux      = convert(line[111:125])
			ratio     = float(line[125:137])
			data = np.append(data, np.array([[time, delta_t, mass, radius, lum_core, lum_tot, flux, ratio]]), axis = 0)
			
	file.close()
	
	return data
All done; thank you for reading.
Gribouillis likes this post
Reply


Messages In This Thread
Numpy Structure and Efficiency - by garynewport - Oct-19-2022, 11:34 AM
RE: Numpy Structure and Efficiency - by garynewport - Oct-19-2022, 12:00 PM
RE: Numpy Structure and Efficiency - by paul18fr - Oct-19-2022, 10:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Efficiency with regard to nested conditionals or and statements Mark17 13 3,378 May-06-2022, 05:16 PM
Last Post: Mark17
  How to use vectorization instead of for loop to improve efficiency in python? PJLEMZ 4 2,519 Feb-06-2021, 09:45 AM
Last Post: paul18fr
  Any suggestions to improve BuySell stock problem efficiency? mrapple2020 0 1,413 May-13-2020, 06:19 PM
Last Post: mrapple2020
  Help improve code efficiency benbrown03 9 4,473 Feb-20-2019, 03:45 PM
Last Post: ichabod801
  Web Scraping efficiency improvement HiImNew 0 2,439 Jun-01-2018, 08:52 PM
Last Post: HiImNew
  Improving Efficiency of SVM by various available kernels Sachtech 0 2,152 Apr-09-2018, 07:29 AM
Last Post: Sachtech
  Still learning - code efficiency, which of these is better? shelzmike 2 3,360 Oct-14-2017, 04:47 AM
Last Post: shelzmike

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020