[Tutor] Help with a Conversion
S. P. Molnar
s.molnar at sbcglobal.net
Thu Jan 5 12:26:59 EST 2017
On 01/05/2017 11:41 AM, Alan Gauld via Tutor wrote:
> On 05/01/17 13:29, S. P. Molnar wrote:
>
>> Fortran II using punched paper tape. Yes, am a rather elderly . . .).
> You are not the only one, there are at least 2 more of us on
> this list that started in that era...
>
>> short program to change frequency to wavelength for a plot of
>> ultraviolet spectra. I have attached a pdf of the program.
> This is a text list so attachments usually get stripped off.
> Please post the code in the body of the email using plain text
> formatting.
>
>> To change the frequency to wave length I did the following:
>>
>> p=1/1e7
> p = 1e-7
>
>> wave_length = p*np.array(frequency)
> I don't really use numpy so don't know what that line does.
> But assuming it applies the multiplication to each array element
> I'd probably use:
>
> wave_lengths = [p*f for f in frequencies]
>
> or possibly
>
> wave_lengths = map(lambda f: p*f, frequencies)
>
> where frequencies was a tuple/list of frequency values.
>
> However...
>
>> (The relationship between wavelength and frequency is: wavelength =
>> 1.0e7/frequency, where 1e7 is the speed of light)
> That formula doesn't look like the one you use above
> if my guess is correct. That would look like:
>
> wave_length = [1e7/f for f in frequencies]
>
> ie positive exponent and division instead of multiplication
>
>> Apparently what I have managed to do is divide each element of the frequency list by 1/1e7.
>>
>> What I want to do is divide 1e7 by each element of the freqquency list.
>> How di I do this?
> Rearrange the equation and use division instead of multiplication
> I think that by calculating 1/p you have made things much more
> complicated - unless there is some subtle arithmetic magic going
> on that I'm missing?
>
Many thanks for the reply and your suggestions.
As it happens, I stumbled on the solution through trial and error.
The correct line is: wave_length = 1e7/np.array(frequency).
All is now well.
--
Stephen P. Molnar, Ph.D. Life is a fuzzy set
www.Molecular-Modeling.net Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
More information about the Tutor
mailing list