# What if you try to make an array with lists w/ non-matching lengths?
try:
k = np.array(([1,2], [3,4,5]))
except Exception as e:
print e
else:
print k.ndim, k.shape
assert k.ndim == 1
assert k.shape == (2,)
1 (2,)
k
array([[1, 2], [3, 4, 5]], dtype=object)
# array multiplication is not matrix muliplication
a0 = arange(4).reshape(2,2)
print a0*a0
print np.dot(a0,a0)
[[0 1] [4 9]] [[ 2 3] [ 6 11]]
#how to prepend a series?
a10 = arange(10)
#how to prepend a series?
a10 = arange(10)
a10
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
# can't use extend on numpy.ndarray
try:
a10.extend(-1)
except Exception as e:
print e
'numpy.ndarray' object has no attribute 'extend'
# append
list0 = [0,1,2]
list0.append(3)
list0
[0, 1, 2, 3]
# extend
list0.extend([-1])
list0
[0, 1, 2, 3, -1]
# insert
list0.insert(0,-2)
list0
[-2, 0, 1, 2, 3, -1]
# use np.insert
np.insert(a10,0,-1)
array([-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9])