'ValueError x and y must have same first dimension, but have shapes (4500,) and (4499,)
#I have a dataframe for a growing polymerization reaction that looks like this:
d_result['M']=
array([70. , 69.99738611, 69.98974828, ..., 0.02669216,
0.02664559, 0.02659911])
Also ;
d_result['time']=
array([ 0. , 0.1, 0.2, ..., 449.7, 449.8, 449.9])
#I intend to produce a plot of 'X' against 'time' for the growing chain versus time;
X = (d_result['M'][0]-d_result['M'][-1])/d_result['M'][0]. # 'X',Monomer conversion
Obtaining the plot:
d_trajectory = d_result
plt.plot(d_trajectory['time'], ((d_trajectory['M'][0]-d_trajectory['M'][:-1])/d_trajectory['M'][0]), 'k')
plt.xlabel('Time')
plt.ylabel('Conversion,X')
#I got the following error: #ValueError: x and y must have the same first dimension, but have shapes (4500,) and (4499,)
Solution 1:[1]
d_trajectory['M'][:-1] doesn't include the last element of the array and is therefore shorter by 1 than d_trajectory['time'], see Understanding slice notation. Try d_trajectory['M'] or d_trajectory['M'][:].
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Roy Bubis |
