Slice an array

0

I'm having problems with the values of x2 when trying to slice to display in graphic 2 nothing appears and I can not see where I'm going wrong?

import matplotlib.pyplot as plt
import numpy as np

xold = np.random.rand()
N = 3000

x1 = np.empty((N))
print("x1:", x1)

for k in range(N):
    x_new = 4*xold*(1 - xold)
    xold = x_new
    x1[k] = x_new

comp = len(x1)
x2 = x1 + 0.25*np.std(x1)*np.random.rand(1,comp)

plt.figure(1)
plt.grid(True)

plt.subplot(2,1,1)
plt.plot(x1[:-1], x1[1:], 'bo')
plt.title('MAPA LOGISTICO 1')
plt.ylabel('x1k)')
plt.xlabel('x1(k-1)')

plt.subplot(2,1,2)
plt.plot(x2[:-1], x2[1:], 'bo')
plt.title('MAPA LOGISTICO 2')
plt.ylabel('x(2k)')
plt.xlabel('x2(k-1)')
plt.show()
    
asked by anonymous 06.11.2018 / 21:12

1 answer

2

The problem is that the way you are calculating, x2 is a two-dimensional array, with the outermost dimension having only one element.

In this way, x2[1:] and x2[:-1] do not return anything because they are empty slices.

One way to solve is to extract the internal vector, that is, before plotting, run:

x2 = x2[0]

The result:

    
06.11.2018 / 21:39