Reputation: 45
I was trying to run a script which is written below. The focus is to print 'rab'.
from numpy import *
import numpy as np
import matplotlib.pyplot as plt
from scipy import interpolate
x = [64, 67, 70.459, 73, 76]
y = [0.697, 0.693, 0.694, 0.698, 0.702]
z = [0.748, 0.745, 0.747, 0.757, 0.763]
delT = 1
f = open('volume-temperature.dat', 'r')
V = []
for line in f:
parts = line.split()
if len(parts) > 1:
#print parts[1]
V.append(parts[1])
f.close()
for M in range(0,5):
T = 0+M*delT
if M == 0:
rab = np.interp(V[M], x, y)
print rab
else:
print M
The problem is while printing 'rab' I am geting this error:
return compiled_interp(x, xp, fp, left, right)
ValueError: object of too small depth for desired array
It looks some fundamental error, But as I am new in Python, so a little help would be appreciated. N.B. V[M] for M = 0 is 70.31
Upvotes: 1
Views: 3495
Reputation: 114956
Your list V
is a list of strings. You must convert these values to floating point numbers before passing them to np.interp
.
You could change this:
V.append(parts[1])
to this:
V.append(float(parts[1]))
Upvotes: 3