PYTHON
how to make a numpy array
>>> x = np.array([2,3,1,0])
>>> x = np.array([2, 3, 1, 0])
>>> x = np.array([[1,2.0],[0,0],(1+1j,3.)]) # note mix of tuple and lists,
and types
>>> x = np.array([[ 1.+0.j, 2.+0.j], [ 0.+0.j, 0.+0.j], [ 1.+1.j, 3.+0.j]])
numpy creating arrays
import numpy as np
# create numpy array
arr = np.array([1, 2, 3, 4, 5])
print(type(arr))
# 1d-array
arr = np.array(42)
print(type(arr))
# 2d-array
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr)
# 3d-array
arr = np.array([[[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [4, 5, 6]]])
print(arr)
# copy an array any changes make to the copy of the array does not affect the original
arr = np.array([1, 2, 3, 4, 5])
x = arr.copy()
arr[0] = 42
print(arr)
# output [42 2 3 4 5]
print(x)
# output [1 2 3 4 5]
# view an array any changes made to the view will affect the original array
arr = np.array([1, 2, 3, 4, 5])
x = arr.view()
arr[0] = 42
print(arr)
# output [42 2 3 4 5]
print(x)
# output [42 2 3 4 5]
create array numpy
import numpy as np
a = np.array([1, 2, 3])
array creation method in numpy
>>> np.arange(10)
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> np.arange(2, 10, dtype=float)
array([ 2., 3., 4., 5., 6., 7., 8., 9.])
>>> np.arange(2, 3, 0.1)
array([ 2. , 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9])
Array Creation in Numpy
>>> import numpy as np
>>> a = np.array([2, 3, 4])
>>> a
array([2, 3, 4])
>>> a.dtype
dtype('int64')
>>> b = np.array([1.2, 3.5, 5.1])
>>> b.dtype
dtype('float64')
create array numpy
a = np.array([1, 2, 3, 4, 5, 6])