Problem while concatenating two numpy arrays

Viewed 64

My aim is to rotate a 1d numpy array by left.For example desired output for numpy array [1,2,3,4] should be [2,3,4,1].

Here is my approach:

import numpy as np

x = np.array([1,2,3,4])
x1 = x[1:]
x2 = x[:1]
print(np.concatenate(x1,x2))

I am facing an error while concatenating. Why is that?

I tried this approach also:

lst = x[1:] + x[:1]
print(np.array(lst))

Although I am getting the desired output I am also getting a error

DeprecationWarning: elementwise comparison failed; this will raise an error in the future.

1 Answers

I already saw this kind of problem to build AES in python. But I didn't used numpy, only list: the step is called ShiftRows

Anyway, you can use: np.roll(your_array, int_shift) For example:

>>> x = np.array([1,2,3,4])
>>> shift_x = np.roll(x, 3)
>>> shift_x
>>> array([2, 3, 4, 1])
Related