I got a list of numbers lets say A = [0.456, 0.4344, 1, -1, 4, 5, 6,8]
how can the function mentioned below be fixed in python using the list of numbers mentioned above and get the six different solutions of 'xf' for lets say the code mentioned below: -
c=2
-
xfmin = 0.432*c
-
xfmax = 0.528*c
-
def xf(a, b):
-
return a+(b-a)*A
-
xfrn= xf(xfmin, xfmax)
-
print "xf=", xfrn
Please use code tags when posting code. See posting guidelines here.
Add an argument to the function and iterate on the list in a for loop: - A = [0.456, 0.4344, 1, -1, 4, 5, 6,8]
-
-
def xf(a, b, item):
-
return a+(b-a)*item
-
-
c=2
-
xfmin = 0.432*c
-
xfmax = 0.528*c
-
-
for item in A:
-
xfrn= xf(xfmin, xfmax, item)
-
print "xf =", xfrn
BV - Moderator
8 1400 bvdet 2,851
Expert Mod 2GB
Please use code tags when posting code. See posting guidelines here.
Add an argument to the function and iterate on the list in a for loop: - A = [0.456, 0.4344, 1, -1, 4, 5, 6,8]
-
-
def xf(a, b, item):
-
return a+(b-a)*item
-
-
c=2
-
xfmin = 0.432*c
-
xfmax = 0.528*c
-
-
for item in A:
-
xfrn= xf(xfmin, xfmax, item)
-
print "xf =", xfrn
BV - Moderator
thank you very much for the reply,
since am a beginner in python I also wanted ask you another question:
let say if you got if you got a sequence of numbers lets say -
A = [3.4, 5.6, 7.7, 9.7]
-
B = [3.5, 4.7.-3.3, 8.7]
-
C = [8.5, 6.7.-8.3, 4.7]
-
-
Z = A*B*C
the value of Z should have four answers
I tried using for loops, lets say for - A = [3.4, 5.6, 7.7, 9.7]
-
B = [3.5, 4.7.-3.3, 8.7]
-
C = [8.5, 6.7.-8.3, 4.7]
-
for i in A:
-
for j in B:
-
for k in C:
-
Z = i*j*k
print z # four possible answers
but it didn't do what I wanted it to do.
Could you please help me out solve this problem.
bvdet 2,851
Expert Mod 2GB
Since the lists are the same length (4) and you want four answers, one could assume you want to multiply the number at index i of list A by the corresponding index of the other two lists. Iterate on A using built-in function enumerate(). - for i, item in enumerate(A):
-
print item*B[i]*C[i]
Is there any other way of doing this other than using enumerate
lets say if the scenario was such that - A = [3.4, 5.6, 7.7, 9.7]
-
B = [3.5, 4.7.-3.3, 8.7]
-
C = [8.5, 6.7.-8.3, 4.7]
-
-
f=2
-
g=4
-
-
z=A*B
-
y=A*C*f
-
u=C*g
-
-
ww=z*y*u
is there any possibility of obtaining four solutions for ww??
and also lets say if you had to use each one of the column of A B and C at each time, is it possible, cause I have tried different methods but am failing to get what am trying to achieve
Even better is to use numpy arrays. Import numpy, convert a,b,c to numpy arrays, and then z=a*b*c does what you want it to do.
I tried using numpy arrays but i was getting this error
Traceback (most recent call last):
File "C:\Python25\GEM SA.py", line 74, in <module>
A = matrix([[a11,a12],[a21,a22]])
File "C:\Python25\Lib\site-packages\numpy\core\defmatrix.py", line 217, in __new__
arr = N.array(data, dtype=dtype, copy=copy)
ValueError: setting an array element with a sequence.
I would be really thankful if someone can help me out as am struggling to get the end result. I am trying to figure out how I can use each value from the each array to get an output result, in total i will get three different results, is there any method available to solve such a scenario - xfrn=array([0.937143,0.885173,1.0329])
-
-
-
theta_freqrn= array([10.1579,9.99248,10.9348])
-
-
kappa_freqrn= array([4.95614, 4, 2])
-
-
arn = array([6.32918, 5, 2])
-
-
Mthetadotrn= array([-1.15940, 1, 4])
-
-
-
-
s = 7.5
-
c = 2.0
-
m = 100.0
-
-
rho = 1.225
-
xcm = 0.5*c
-
-
-
e = xfrn/c-0.25
-
-
-
vel = zeros((3500,1),float)
-
freq1 = zeros((3500,1),float)
-
freq2 = zeros((3500,1),float)
-
freq3 = zeros((3500,1),float)
-
freq4 = zeros((3500,1),float)
-
damp1 = zeros((3500,1),float)
-
damp2 = zeros((3500,1),float)
-
damp3 = zeros((3500,1),float)
-
damp4 = zeros((3500,1),float)
-
-
vstart = 1.0
-
vinc = 0.1
-
for icount in range(3500):
-
V=vstart + icount*vinc
-
-
a11 = (m*s*s*s*c)/3.0
-
a12 = m*s*s*(c*c/2.0-c*xfrn)/2.0
-
a21 = a12
-
a22 = m*s*(c*c*c/3.0-c*c*xfrn+xfrn*xfrn*c)
-
-
A = matrix([[a11,a12],[a21,a22]])
-
Ainv = linalg.inv(A)
-
-
k1 = ((kappa_freqrn*arn)**2)*a11
-
k2 = ((theta_freqrn*arn)**2)*a22
-
-
c11 = (rho*V*c*s*s*s*arn)/6.0
-
c12 = 0
-
c21 = -(rho*V*c*c*s*s*e*arn)/4.0
-
c22 = -(rho*V*c*c*c*s*Mthetadotrn)/8.0
-
-
C = matrix([[c11,c12],[c21,c22]])
-
-
AC = -Ainv*C
-
-
k11 = k1
-
k12 = (rho*V*V*c*s*s*arn)/4.0
-
k21 = 0
-
k22 = k2 - (rho*V*V*c*c*s*e*arn)/2.0
-
K = matrix([[k11,k12],[k21,k22]])
-
-
AK = -Ainv*K
-
-
matrix_bind_columns = concatenate((AK,AC),axis=1)
-
M = concatenate((matrix([[0.0,0.0,1.0,0.0],[0.0,0.0,0.0,1.0]]),matrix_bind_columns),axis=0)
-
-
Meig = linalg.eig(M)[0]
-
-
vel[icount] = V
-
freq1[icount] = abs(Meig[0])
-
damp1[icount] = -100.0*real(Meig[0])/freq1[icount]
-
freq1[icount] = freq1[icount]/2*math.pi
-
freq2[icount] = abs(Meig[1])
-
damp2[icount] = -100.0*real(Meig[1])/freq2[icount]
-
freq2[icount] = freq2[icount]/2*math.pi
-
freq3[icount] = abs(Meig[2])
-
damp3[icount] = -100.0*real(Meig[2])/freq3[icount]
-
freq3[icount] = freq3[icount]/2*math.pi
-
freq4[icount] = abs(Meig[3])
-
damp4[icount] = -100.0*real(Meig[3])/freq4[icount]
-
freq4[icount] = freq4[icount]/2*math.pi
-
-
if damp3[icount] < 0: goes below zero
-
break
-
-
ab = (damp3[icount-1])
-
-
-
bc = (damp3[icount])
-
-
-
Vf_min = V-0.1
-
-
-
Vf_max = V
-
-
-
def flutter_speed(ab,bc,Vf_min,Vf_max):
-
return (Vf_min+(Vf_max - Vf_min)*(-(ab)/(bc - ab)))
-
Vf = flutter_speed(ab,bc,Vf_min,Vf_max)
-
print Vf
I am wondering if anyone can help me fix the array problem out?? If someone can give me feedback on where I am going wrong??
Do you mean just for the multiplication? - In [1]: from numpy import *
-
-
In [2]: A=array([3.4,5.6,7.7,9.7])
-
-
In [3]: B=array([3.5,4.7,-3.3,8.7])
-
-
In [4]: C=array([8.5,6.7,-8.3,4.7])
-
-
In [5]: f=2
-
-
In [6]: g=4
-
-
In [7]: z=A*B
-
-
In [8]: y=A*C*f
-
-
In [9]: u=C*g
-
-
In [10]: ww=z*y*u
-
-
In [11]: z
-
Out[11]: array([ 11.9 , 26.32, -25.41, 84.39])
-
-
In [12]: y
-
Out[12]: array([ 57.8 , 75.04, -127.82, 91.18])
-
-
In [13]: u
-
Out[13]: array([ 34. , 26.8, -33.2, 18.8])
-
-
In [14]: ww
-
Out[14]: array([ 23385.88 , 52931.41504, -107830.48584, 144659.98776])
-
-
If it's something else, maybe start a new post.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mikkel christensen |
last post by:
Hi there
I wonder if any of you could point me in a direction where I can find some
usefull information about coding standarts.
I have some generel experiense in programming but I lack many...
|
by: Berthold Höllmann |
last post by:
I have a default coding header
# -*- coding: iso-8859-15 -*-
in my python files. I now have Problems with this settings. I
swithched to Python 2.4.1 under Windows. When I import files with the...
|
by: manning_news |
last post by:
Has anyone had a problem with Access 2003 not saving their coding?
I've been using 2003 for a couple of months now and just this week
noticed that some coding I'd done for a database was not there...
|
by: Natt Serrasalmus |
last post by:
After years of operating without any coding standards whatsoever, the
company that I recently started working for has decided that it might be a
good idea to have some. I'm involved in this...
|
by: |
last post by:
I was wondering, I don't mean to be rude at all to ask
this but i'd like to know if any of you guys have had
problems in relating to getting paid a fair amount when it
comes to coding.
...
|
by: Simon Hengel |
last post by:
Hello,
we are hosting a python coding contest an we even managed to provide a
price for the winner...
http://pycontest.net/
The contest is coincidentally held during the 22c3 and we will be...
|
by: Robert Baer |
last post by:
The homepage i have had up and seemingly working is:
http://oil4lessllc.com/
However, the validator has so many complaints, and being so
incompetent, i have no clue as to how to fix it all.
Would...
|
by: juliehg |
last post by:
Hi,
I'm currently using MS Access 2000 to keep all my actors measurements, resumes and personal details on a database.
To upload their details onto our website, I have built an event so when I...
|
by: pat |
last post by:
CodeCheck Coding Standard's Support
As a free service to our customers we offer support in developing
"rule-files" for automating corporate coding standards.
If you have a coding standard that...
|
by: LayneMitch via WebmasterKB.com |
last post by:
Hello. It's me again with another question that should generate a lot of
responses.
As mentioned before, I'm working on my first site (hopefully I'll be done
soon and can move on to other...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |