Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8318845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:07:16+00:00 2026-06-08T22:07:16+00:00

In a monte-carlo simulation I store a summary of each run in a data

  • 0

In a monte-carlo simulation I store a summary of each run in a data file, in which each column contains either a parameter or one of the result values. So I end up with a large data file in which up to 40 columns of data is stored, in which many rows don’t have anything to do with others.

Say, for example, this file looks like that:

#param1    param2    result1    result2
1.0        1.0       3.14       6.28
1.0        2.0       6.28       12.56
...
2.0        1.0       1.14       2.28
2.0        2.0       2.28       4.56

Since I often want to study the dependence of one of the results on one of the parameters, I both need to group by the 2nd parameter and sort by the 1st one. Also, I might want to filter out rows depending on any parameters.

I started writing my own class for this, but it seems harder than one might guess. Now my question: Is there any library, that does this already? Or, since I am familiar with SQL, would it be difficult to write an SQL backend for, say, SQLAlchemy, that allows me to do simple SQL queries on my data? As far as I know, this would provide everything I need.


Based on the answer of cravoori (or at least the one in the link he/she posted), here is a nice and short solution to my problem:

#!/usr/bin/python2

import numpy as np
import sqlite3 as sql

# number of columns to read in
COLUMNS = 31

# read the file. My columns are always 18chars long. the first line are the names
data = np.genfromtxt('compare.dat',dtype=None,delimiter=18, autostrip=True,
                     names=True, usecols=range(COLUMNS), comments=None)

# connect to the database in memory
con = sql.connect(":memory:")

# create the table 'data' according to the column names
con.execute("create table data({0})".format(",".join(data.dtype.names)))

# insert the data into the table
con.executemany("insert into data values (%s)" % ",".join(['?']*COLUMNS),
                data.tolist())

# make some query and create a numpy array from the result
res = np.array(con.execute("select DOS_Exponent,Temperature,Mobility from data ORDER \
    BY DOS_Exponent,Temperature ASC").fetchall())

print res
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:07:18+00:00Added an answer on June 8, 2026 at 10:07 pm

    Seeing that the data is delimited, one option is to import the file into an in-memory SQLite database via the csv module, example linked below. Sqlite supports most SQL clauses

    Import data into SQLite db

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that does some Monte Carlo simulation. For each run, a
I'm writing a Monte Carlo algorithm, in which at one point I need to
I have a data frame that I am running a Monte Carlo simulation on,
I have a program which performs a Monte Carlo-type simulation. Currently I have written
I have written some code which performs a Monte Carlo simulation and produces curves
I use R and I implemented a Monte Carlo simulation in R which takes
I was trying to write a simple Monte Carlo simulation program. To be exact,
I've been tasked with taking an existing single threaded monte carlo simulation and optimising
Whenever I run large scale monte carlo simulations in S-Plus, I always end up
I am rewriting a Monte Carlo simulation model in MATLAB with an emphasis on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.