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 993713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:28:03+00:00 2026-05-16T06:28:03+00:00

hey guys, this is very confusing… i am trying to find the minimum of

  • 0

hey guys, this is very confusing…

i am trying to find the minimum of an array by:

for xpre in range(100): #used pre because I am using vapor pressures with some x molarity
        xvalue=xarray[xpre]
        for ppre in range(100): #same as xpre but vapor pressures for pure water, p
            pvalue=parray[p]
            d=math.fabs(xvalue-pvalue) #d represents the difference(due to vapor pressure lowering, a phenomenon in chemistry)
            darray.append(d) #darray stores the differences
        mini=min(darray) #mini is the minimum value in darray
        darr=[] #this is to make way for a new set of floats

all the arrays (xarr,parr,darr)are already defined and what not. they have 100 floats each

so my question is how would I find the pvap and the xvap @ which min(darr) is found?

edit
have changed some variable names and added variable descriptions, sorry guys

  • 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-05-16T06:28:04+00:00Added an answer on May 16, 2026 at 6:28 am

    A couple things:

    1. Try enumerate
    2. Instead of darr being a list, use a dict and store the dvp values as keys, with the xindex and pindex variables as values

    Here’s the code

    for xindex, xvalue in enumerate(xarr):
      darr = {}
      for pindex, pvalue in enumerate(parr):
        dvp = math.fabs(xvalue - pvalue)
        darr[dvp] = {'xindex': xindex, 'pindex': pindex}
      mini = min(darr.keys())
      minix = darr[mini]['xindex']
      minip = darr[mini]['pindex']
      minindex = darr.keys().index(mini)
    
    
      print "minimum_index> {0}, is the difference of xarr[{1}] and parr[{2}]".format(minindex, minix, minip)
      darr.clear()
    

    Explanation

    The enumerate function allows you to iterate over a list and also receive the index of the item. It is an alternative to your range(100). Notice that I don’t have the line where I get the value at index xpre, ppre, this is because the enumerate function gives me both index and value as a tuple.

    The most important change, however, is that instead of your darr being a list like this:

    [130, 18, 42, 37 ...]
    

    It is now a dictionary like this:

    {
      130: {'xindex': 1, 'pindex': 4},
      18: {'xindex': 1, 'pindex': 6},
      43: {'xindex': 1, 'pindex': 9},
      ...
    }
    

    So now, instead of just storing the dvp values alone, I am also storing the indices into x and p which generated those dvp values. Now, if I want to know something, say, Which x and p values produce the dvp value of 43? I would do this:

    xindex = darr[43]['xindex']
    pindex = darr[43]['pindex']
    x = xarr[xindex]
    p = parr[pindex]
    

    Now x and p are the values in question.

    Note I personally would store the values which produced a particular dvp, and not the indices of those values. But you asked for the indices so I gave you that answer. I’m going to assume that you have a reason for wanting to handle indices like this, but in Python generally you do not find yourself handling indices in this way when you are programming in Pythonic manner. This is a very C way of doing things.

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

Sidebar

Related Questions

Hey guys I am getting this exception when trying to run the query Column
Hey guys i'm trying to convert url which looks like this example.com/sometype/author-name/sort-date or example.com/sometype/author-name/sort-date/something-value/
hey guys, i have very small issue please see the code below // this
Hey guys, this should be quite simple to answer.... Im using XSB Prolog...trying to
Hey guys I'm trying to identify this javascript image gallery viewer on Tumblr, I
Hey guys I have an array like this print_r($grouparray); Array ( [0] => Array
Hey guys, I've struggled with this for a bit and don't seem to find
Hey Guys my goal for this multi dimensional array is to document the answers
Hey guys. This is a very simple question, I'm sure, but I'm getting myself
Hey guys this is a bit of a homework puzzle I'm working on and

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.