>>> x = 42
>>> xs = [1, 2, 3]
>>> xs.insert(0, x)
>>> xs
[42, 1, 2, 3]
How it works:
list.insert(index, value)
Insert an item at a given position. The first argument is the index of the element before which to insert, so xs.insert(0, x) inserts at the front of the list, and xs.insert(len(xs), x) is equivalent to xs.append(x). Negative values are treated as being relative to the end of the list.
>>> x = 42
>>> xs = [1, 2, 3]
>>> xs.insert(0, x)
>>> xs
[42, 1, 2, 3]
How it works:
list.insert(index, value)
Insert an item at a given position. The first argument is the index of the element before which to insert, so xs.insert(0, x) inserts at the front of the list, and xs.insert(len(xs), x) is equivalent to xs.append(x). Negative values are treated as being relative to the end of the list.
>>> x = 42
>>> xs = [1, 2, 3]
>>> [x] + xs
[42, 1, 2, 3]
Note: don't use list as a variable name.
Videos
Another way to do that would be to use numpy.concatenate . Example -
np.concatenate([[88],a,[77]])
Demo -
In [62]: a = np.array([2, 56, 4, 8, 564])
In [64]: np.concatenate([[88],a,[77]])
Out[64]: array([ 88, 2, 56, 4, 8, 564, 77])
You can pass the list of indices to np.insert :
>>> np.insert(a,[0,5],[88,77])
array([ 88, 2, 56, 4, 8, 564, 77])
Or if you don't know the length of your array you can use array.size to specify the end of array :
>>> np.insert(a,[0,a.size],[88,77])
array([ 88, 2, 56, 4, 8, 564, 77])
Simplest way:
a = np.array([1 + 2j, 5 + 7j])
a = np.insert(a, 0, 0)
Then:
>>> a
array([ 0.+0.j, 1.+2.j, 5.+7.j])
Note that this creates a new array, it does not actually insert the 0 into the original array.
There are several alternatives to np.insert, all of which also create a new array:
In [377]: a
Out[377]: array([ 1.+2.j, 5.+7.j])
In [378]: np.r_[0, a]
Out[378]: array([ 0.+0.j, 1.+2.j, 5.+7.j])
In [379]: np.append(0, a)
Out[379]: array([ 0.+0.j, 1.+2.j, 5.+7.j])
In [380]: np.concatenate([[0], a])
Out[380]: array([ 0.+0.j, 1.+2.j, 5.+7.j])
In [381]: np.hstack([0, a])
Out[381]: array([ 0.+0.j, 1.+2.j, 5.+7.j])
In [382]: np.insert(a, 0, 0)
Out[382]: array([ 0.+0.j, 1.+2.j, 5.+7.j])
An alternative is "horizontal stack" (also creates a new array):
np.hstack((0,a))