0

So I'm not the best at python but I need to create this program for one of my courses and I keep getting this error.

Basically I have w_array = linspace(0.6, 1.1, 11), then I have zq = array([1, 1, w_array, 1])

and it comes up with the error message:

ValueError: setting an array element with a sequence.

the basic function of the code is to take a bezier spline aerofoil, with control points and weights, run the data in xfoil and print cd and cl values, but this addition is to show a graph of the range of cd for a certain control point.

hope it makes sense, any help would be greatly appreciated.

5
  • What is the error? Would be nice to know Commented Feb 14, 2014 at 16:21
  • Word of warning: wanting an array to be made up of two integers, and then an array of floats, and then another integer, is a strange thing to want. You may have taken a wrong turn. Commented Feb 14, 2014 at 16:29
  • the error was 'setting an array element with a sequence' and @dsm thats how the uni wanted us to go about the code,considering i have such little knowledge in python i have no clue! Commented Feb 14, 2014 at 16:39
  • @user3310983: well, I can't speak to what your university requested, but that's not something you'd ordinarily do in numpy. If you do that, say using dtype=object, standard numpy vector arithmetic won't work any more. But under the circumstances I'd do whatever the people grading you say to. :^) Commented Feb 14, 2014 at 16:43
  • this is what they wanted 'A function parameter sweep(w array,cl,file path,xfoil path) which is the same as run xfoil wcl() , but where w array is an array of weights for the control point at [0.4, 0.2] . The function should return the cor- responding array of C D values. Example: >>> w array = linspace (0.6 , 1.2 , 11) >>> print parameter sweep ( w array , 0.843 , file path , xfoil path ) [ 0.00744 0.00697 0.00669 0.00655 0.0065 0.00681 0.00706 0.00721 0.00733 0.00746 0.00759]' Commented Feb 14, 2014 at 16:45

2 Answers 2

2

If you want zq be an array containing both ints and lists, use parameter dtype:

In [300]: zq = array([1, 1, w_array, 1], dtype=object)

In [301]: zq
Out[301]: 
array([1, 1,
       array([ 0.6 ,  0.65,  0.7 ,  0.75,  0.8 ,  0.85,  0.9 ,  0.95,  1.  ,
        1.05,  1.1 ]),
       1], dtype=object)
Sign up to request clarification or add additional context in comments.

Comments

1

Is this your intended result?

In [2]:
numpy.hstack((1,1,numpy.linspace(0.6,1.1,11),1))
Out[2]:
array([ 1.  ,  1.  ,  0.6 ,  0.65,  0.7 ,  0.75,  0.8 ,  0.85,  0.9 ,
        0.95,  1.  ,  1.05,  1.1, 1. ])

You probably want the resulting array to have float64 dtypes rather than object, a mixed bag of dtypes, as @DSM pointed out.

5 Comments

when i use it it gives me an error ' TypeError: hstack() takes exactly 1 argument (2 given) ' but yes thats essentially what i want as the result
make sure you have the right number of '(' and ')'. :-)
ok i'll have a quick look, sorry about the questions, i'm just struggling with getting to grips with python haha
its still coming up with errors, im not entirely sure my code is correct is correct aha
Check the doc out docs.scipy.org/doc/numpy/reference/generated/numpy.hstack.html. You should be fine if you correctly put all the data in a tuple.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.