1

I am solving a ODE as follows:

import numpy as np
import scipy as sp
import math
from math import *
from scipy.integrate import odeint
import matplotlib.pyplot as plt

def g(y, x):
    y0 = y[0]
    return x   #formula##

# Initial conditions on y, y' at x=0
init = 0   #value##
# First integrate from 0 to 100
xplotval=np.linspace(4,8,4)  #linspacefunction
print(xplotval)

I am getting output as:

[[ 7.         ]
 [ 5.76455273 ]
 [ 5.41898906 ]
 [ 6.49185668 ]]

I'd like to output a single dimensional array as follows:

[7., 5.76455273, 5.41898906, 6.49185668]

How can I?

1
  • Please avoid posting screenshots. Just copypaste your output. Commented Sep 14, 2015 at 15:30

2 Answers 2

1

Maybe you want flatten:

print(xplotval.flatten())

Unless you actually want the transposed vector, which you would get with numpy.transpose:

print(np.transpose(xplotval))
Sign up to request clarification or add additional context in comments.

8 Comments

No it is not working as I needed. I need as array. It not makes array!!
the elements are not comma seperated. I am getting output as [7. 5.76455273 5.41898906 6.49185668]. I want it as comma seperated
You can output any array separated by commas with string.join(array, ","). In your case print(string.join([str(x) for x in np.transpose(xplotval)], ", ")) should work.
what you mean by string? I get as undefined variable
You have to import string first, of course.
|
0

You can simply use list comprehension, something like:

oneD = [l[0] for l in xplotval]

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.