1-dimensionales Array
import numpy as np
sample_ndarray_1d = np.array([1,2,3,4,5])
print("sample_ndarray_1d: ", sample_ndarray_1d)
sample_ndarray_1d: [1 2 3 4 5]
Ein zweidimensionales Array
import numpy as np
sample_ndarray_2d = np.array([[1,2,3,4,5],[6,7,8,9,10]])
print("sample_ndarray_2d: ", sample_ndarray_2d)
sample_ndarray_2d: [[ 1 2 3 4 5]
1-dimensionales Array
import numpy as np
sample_ndarray_1d = np.array([1,2,3,4,5])
print("sample_ndarray_1d[0]: ", sample_ndarray_1d[0])
print("sample_ndarray_1d[1]: ", sample_ndarray_1d[1])
print("sample_ndarray_1d[2]: ", sample_ndarray_1d[2])
print("sample_ndarray_1d[3]: ", sample_ndarray_1d[3])
print("sample_ndarray_1d[4]: ", sample_ndarray_1d[4])
print("sample_ndarray_1d[-1]: ", sample_ndarray_1d[-1])
sample_ndarray_1d[0]: 1
sample_ndarray_1d[1]: 2
sample_ndarray_1d[2]: 3
sample_ndarray_1d[3]: 4
sample_ndarray_1d[4]: 5
sample_ndarray_1d[-1]: 5
Ein zweidimensionales Array
import numpy as np
sample_ndarray_2d = np.array([[1,2,3,4,5],[6,7,8,9,10]])
print("sample_ndarray_2d[0,0]: ", sample_ndarray_2d[0,0])
print("sample_ndarray_2d[0,1]: ", sample_ndarray_2d[0,1])
print("sample_ndarray_2d[0,2]: ", sample_ndarray_2d[0,2])
print("sample_ndarray_2d[0,3]: ", sample_ndarray_2d[0,3])
print("sample_ndarray_2d[0,4]: ", sample_ndarray_2d[0,4])
print("sample_ndarray_2d[1,0]: ", sample_ndarray_2d[1,0])
print("sample_ndarray_2d[1,1]: ", sample_ndarray_2d[1,1])
print("sample_ndarray_2d[1,2]: ", sample_ndarray_2d[1,2])
print("sample_ndarray_2d[1,3]: ", sample_ndarray_2d[1,3])
print("sample_ndarray_2d[1,4]: ", sample_ndarray_2d[1,4])
sample_ndarray_2d[0,0]: 1
sample_ndarray_2d[0,1]: 2
sample_ndarray_2d[0,2]: 3
sample_ndarray_2d[0,3]: 4
sample_ndarray_2d[0,4]: 5
sample_ndarray_2d[1,0]: 6
sample_ndarray_2d[1,1]: 7
sample_ndarray_2d[1,2]: 8
sample_ndarray_2d[1,3]: 9
sample_ndarray_2d[1,4]: 10
1-dimensionales Array
import numpy as np
sample_ndarray_1d = np.array([1,2,3,4,5])
print("sample_ndarray_1d: ", sample_ndarray_1d)
sample_ndarray_1d: [1 2 3 4 5]
start_id = 1
end_id = 3
print("Artikelnummern "1" bis "3":",sample_ndarray_1d[start_id:end_id+1])
print("Artikelnummer "First" bis "3":",sample_ndarray_1d[:end_id+1])
print("Artikelnummer "1" bis "zuletzt":",sample_ndarray_1d[start_id:])
print("Alle Elemente:",sample_ndarray_1d[:])
Artikelnummern "1" bis "3":[2 3 4]
Artikelnummer "First" bis "3":[1 2 3 4]
Artikelnummer "1" bis "zuletzt":[2 3 4 5]
Alle Elemente:[1 2 3 4 5]
1-dimensionales Array
import numpy as np
sample_ndarray_1d = np.array([1,2,3,4,5])
print("Array-Länge:",len(sample_ndarray_1d))
Array-Länge: 5
Ein zweidimensionales Array
import numpy as np
sample_ndarray_2d = np.array([[1,2,3,4,5],[6,7,8,9,10]])
print("Länge der übergeordneten Liste:",len(sample_ndarray_2d)) ###Übergeordnete Liste
print("Länge der ersten untergeordneten Liste:",len(sample_ndarray_2d[0])) ###Erste Kinderliste
Länge der Elternliste: 2
Länge der ersten Kinderliste: 5
1-dimensionales Array
import numpy as np
sample_ndarray_1d = np.array([1,2,3,4,5])
print("Arraygröße:",sample_ndarray_1d.shape)
Arraygröße:(5,)
Ein zweidimensionales Array
import numpy as np
sample_ndarray_2d = np.array([[1,2,3,4,5],[6,7,8,9,10]])
print("Arraygröße:",sample_ndarray_2d.shape)
Arraygröße:(2, 5)
1-dimensionales Array
import numpy as np
sample_ndarray_1d = np.array([1,2,3,4,5])
print("Anzahl der Dimensionen:",sample_ndarray_1d.ndim)
Anzahl der Dimensionen: 1
Ein zweidimensionales Array
import numpy as np
sample_ndarray_2d = np.array([[1,2,3,4,5],[6,7,8,9,10]])
print("Anzahl der Dimensionen:",sample_ndarray_2d.ndim)
Anzahl der Dimensionen: 2
1-dimensionales Array
import numpy as np
sample_ndarray_1d = np.array([1,2,3,4,5])
print("Elementanzahl:",sample_ndarray_1d.size)
Anzahl der Elemente: 5
Ein zweidimensionales Array
import numpy as np
sample_ndarray_2d = np.array([[1,2,3,4,5],[6,7,8,9,10]])
print("Elementanzahl:",sample_ndarray_2d.size)
Anzahl der Elemente: 10
1-dimensionales Array
import numpy as np
sample_ndarray = np.array([1,2,3,4,5])
print("Speichertyp:",type(sample_ndarray))
Speichertyp:<class 'numpy.ndarray'>
1-dimensionales Array
import numpy as np
sample_ndarray = np.array([1,2,3,4,5])
print("Elementdatentyp:",sample_ndarray.dtype)
Elementdatentyp: int32
1-dimensionales Array
import numpy as np
sample_ndarray_1d = np.array([1,2,3,4,5])
print("sample_ndarray_1d: ",sample_ndarray_1d)
sample_ndarray_1d: [1 2 3 4 5]
deleted_ndarray_1d = np.delete(sample_ndarray_1d,2,0)
print("deleted_ndarray_1d: ",deleted_ndarray_1d)
deleted_ndarray_1d: [1 2 4 5]
Ein zweidimensionales Array[Löschen: Zeile]
import numpy as np
sample_ndarray_2d = np.array([[1,2,3,4,5],[6,7,8,9,10]])
print("sample_ndarray_2d: ", sample_ndarray_2d)
sample_ndarray_2d: [[ 1 2 3 4 5]
[ 6 7 8 9 10]]
deleted_ndarray_2d = np.delete(sample_ndarray_2d,0,0)
print("deleted_ndarray_2d: ",deleted_ndarray_2d)
deleted_ndarray_2d: [[ 6 7 8 9 10]]
Ein zweidimensionales Array[Löschen: Spalte]
import numpy as np
sample_ndarray_2d = np.array([[1,2,3,4,5],[6,7,8,9,10]])
print("sample_ndarray_2d: ", sample_ndarray_2d)
sample_ndarray_2d: [[ 1 2 3 4 5]
[ 6 7 8 9 10]]
deleted_ndarray_2d = np.delete(sample_ndarray_2d,2,1)
print("deleted_ndarray_2d: ",deleted_ndarray_2d)
deleted_ndarray_2d: [[ 1 2 4 5]
[ 6 7 9 10]]
1-dimensionales Array
import numpy as np
A = np.array([1,2,3])
B = np.array([4,5,6])
C = np.concatenate((A,B),axis=0)
print("joint ndarray (Horizontal): ", C)
joint ndarray (Horizontal): [1 2 3 4 5 6]
Ein zweidimensionales Array
import numpy as np
A = np.array([[1,2,3],[4,5,6]])
B = np.array([[7,8,9],[10,11,12]])
C = np.concatenate((A,B),axis=0)
print("joint ndarray (Vertical): ", C)
joint ndarray (Vertical): [[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]
D = np.concatenate((A,B),axis=1)
print("joint ndarray (Horizontal): ", D)
joint ndarray (Horizontal): [[ 1 2 3 7 8 9]
[ 4 5 6 10 11 12]]
1-dimensionales Array
import numpy as np
A = np.array([1,2,3])
B = np.array([4,5,6])
C = np.block([[A,B]])
print("joint ndarray (Vertical): ", C)
joint ndarray (Vertical): [[1 2 3]
[4 5 6]]
D = np.block([[A],[B]])
print("joint ndarray (Horizontal): ", D)
joint ndarray (Horizontal): [1 2 3 4 5 6]
Ein zweidimensionales Array
import numpy as np
A = np.array([[1,2,3],[4,5,6]])
B = np.array([[7,8,9],[10,11,12]])
C = np.block([[A],[B]])
print("joint ndarray (Vertical): ", C)
joint ndarray (Vertical): [[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]
D = np.block([[A,B]])
print("joint ndarray (Horizontal): ", D)
joint ndarray (Horizontal): [[ 1 2 3 7 8 9]
[ 4 5 6 10 11 12]]
1-dimensionales Array
import numpy as np
A = np.array([1,2,3])
B = np.array([4,5,6])
C = np.vstack((A,B))
print("joint ndarray (Vertical): ", C)
joint ndarray (Vertical): [[1 2 3]
[4 5 6]]
D = np.hstack((A,B))
print("joint ndarray (Horizontal): ", D)
joint ndarray (Horizontal): [1 2 3 4 5 6]
Ein zweidimensionales Array
import numpy as np
A = np.array([[1,2,3],[4,5,6]])
B = np.array([[7,8,9],[10,11,12]])
C = np.vstack((A,B))
print("joint ndarray (Vertical): ", C)
joint ndarray (Vertical): [[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]
D = np.hstack((A,B))
print("joint ndarray (Horizontal): ", D)
joint ndarray (Horizontal): [[ 1 2 3 7 8 9]
[ 4 5 6 10 11 12]]
Ein zweidimensionales Array
import numpy as np
A = np.array([[1,2,3],[4,5,6]])
B = np.array([[7,8,9],[10,11,12]])
C = np.dstack((A,B))
print("stack ndarray: ", C)
stack ndarray: [[[ 1 7]
[ 2 8]
[ 3 9]]
[[ 4 10]
[ 5 11]
[ 6 12]]]
print("Arraygröße:",C.shape)
print("Anzahl der Dimensionen:",C.ndim)
Arraygröße:(2, 3, 2)
Anzahl der Dimensionen: 3
Ein zweidimensionales Array
import numpy as np
A = np.array([[1,2,3],[4,5,6]])
B = np.array([[7,8,9],[10,11,12]])
C = np.stack((A,B))
print("stack ndarray: ", C)
stack ndarray: [[[ 1 2 3]
[ 4 5 6]]
[[ 7 8 9]
[10 11 12]]]
print("Arraygröße:",C.shape)
print("Anzahl der Dimensionen:",C.ndim)
Arraygröße:(2, 2, 3)
Anzahl der Dimensionen: 3
1-dimensionales Array
import numpy as np
sample_ndarray_1d = np.array([1,2,3,4,5,6])
print("sample_ndarray_1d: ",sample_ndarray_1d)
sample_ndarray_1d: [1 2 3 4 5 6]
split_ndarray_1d = np.split(sample_ndarray_1d,2)
print("split_ndarray_1d[0]: ",split_ndarray_1d[0])
print("split_ndarray_1d[1]: ",split_ndarray_1d[1])
split_ndarray_1d[0]: [1 2 3]
split_ndarray_1d[1]: [4 5 6]
Ein zweidimensionales Array[Trennlinie]
import numpy as np
sample_ndarray_2d = np.array([[1,2,3,4,5,6],[7,8,9,10,11,12]])
print("sample_ndarray_2d: ",sample_ndarray_2d)
sample_ndarray_2d: [[ 1 2 3 4 5 6]
[ 7 8 9 10 11 12]]
split_ndarray_2d = np.split(sample_ndarray_2d,2,axis=0)
print("split_ndarray_2d[0]: ",split_ndarray_2d[0])
print("split_ndarray_2d[1]: ",split_ndarray_2d[1])
split_ndarray_2d[0]: [[1 2 3 4 5 6]]
split_ndarray_2d[1]: [[ 7 8 9 10 11 12]]
Ein zweidimensionales Array[Teilen: Spalte]
import numpy as np
sample_ndarray_2d = np.array([[1,2,3,4,5,6],[7,8,9,10,11,12]])
print("sample_ndarray_2d: ",sample_ndarray_2d)
sample_ndarray_2d: [[ 1 2 3 4 5 6]
[ 7 8 9 10 11 12]]
split_ndarray_2d = np.split(sample_ndarray_2d,2,axis=1)
print("split_ndarray_2d[0]: ",split_ndarray_2d[0])
print("split_ndarray_2d[1]: ",split_ndarray_2d[1])
split_ndarray_2d[0]: [[1 2 3]
[7 8 9]]
split_ndarray_2d[1]: [[ 4 5 6]
[10 11 12]]
Ein zweidimensionales Array[Trennlinie]
import numpy as np
sample_ndarray_2d = np.array([[1,2,3,4,5,6],[7,8,9,10,11,12]])
print("sample_ndarray_2d: ",sample_ndarray_2d)
sample_ndarray_2d: [[ 1 2 3 4 5 6]
[ 7 8 9 10 11 12]]
split_ndarray_2d = np.vsplit(sample_ndarray_2d,2)
print("split_ndarray_2d[0]: ",split_ndarray_2d[0])
print("split_ndarray_2d[1]: ",split_ndarray_2d[1])
split_ndarray_2d[0]: [[1 2 3 4 5 6]]
split_ndarray_2d[1]: [[ 7 8 9 10 11 12]]
Ein zweidimensionales Array[Teilen: Spalte]
import numpy as np
sample_ndarray_2d = np.array([[1,2,3,4,5,6],[7,8,9,10,11,12]])
print("sample_ndarray_2d: ",sample_ndarray_2d)
sample_ndarray_2d: [[ 1 2 3 4 5 6]
[ 7 8 9 10 11 12]]
split_ndarray_2d = np.hsplit(sample_ndarray_2d,2)
print("split_ndarray_2d[0]: ",split_ndarray_2d[0])
print("split_ndarray_2d[1]: ",split_ndarray_2d[1])
split_ndarray_2d[0]: [[1 2 3]
[7 8 9]]
split_ndarray_2d[1]: [[ 4 5 6]
[10 11 12]]
3D-Array
import numpy as np
sample_ndarray_3d = np.array([[[1,2],[3,4]],[[5,6],[7,8]]])
print("sample_ndarray_3d: ",sample_ndarray_3d)
sample_ndarray_3d: [[[1 2]
[3 4]]
[[5 6]
[7 8]]]
split_ndarray_3d = np.dsplit(sample_ndarray_3d,2)
print("split_ndarray_3d[0]: ",split_ndarray_3d[0])
print("split_ndarray_3d[1]: ",split_ndarray_3d[1])
split_ndarray_3d[0]: [[[1]
[3]]
[[5]
[7]]]
split_ndarray_3d[1]: [[[2]
[4]]
[[6]
[8]]]
1-dimensionales Array
import numpy as np
zero_ndarray_1d = np.zeros(5)
print("zero_ndarray_1d: ",zero_ndarray_1d)
zero_ndarray_1d: [0. 0. 0. 0. 0.]
Ein zweidimensionales Array
import numpy as np
zero_ndarray_2d = np.zeros((2,3))
print("zero_ndarray_2d: ",zero_ndarray_2d)
zero_ndarray_2d: [[0. 0. 0.]
[0. 0. 0.]]
Kopie in Arraygröße
import numpy as np
sample_ndarray = np.array([[1,2,3,4,5],[6,7,8,9,10]])
zero_ndarray = np.zeros_like(sample_ndarray)
print("zero ndarray: ",zero_ndarray)
zero ndarray: [[0 0 0 0 0]
[0 0 0 0 0]]
Einheitenarray[Offset: Keine]
import numpy as np
identity_ndarray = np.eye(3)
print("identity ndarray: ",identity_ndarray)
identity ndarray: [[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
Einheitenarray[Offset: Ja]
import numpy as np
offset = 1
identity_ndarray = np.eye(3,k=offset)
print("identity ndarray: ",identity_ndarray)
identity ndarray: [[0. 1. 0.]
[0. 0. 1.]
[0. 0. 0.]]
import numpy as np
offset = -1
identity_ndarray = np.eye(3,k=offset)
print("identity ndarray: ",identity_ndarray)
identity ndarray: [[0. 0. 0.]
[1. 0. 0.]
[0. 1. 0.]]
Einheitenarray[Offset: Keine]
import numpy as np
identity_ndarray = np.identity(3)
print("identity ndarray: ",identity_ndarray)
1-dimensionales Array
import numpy as np
empty_ndarray_1d = np.empty(5)
print("empty_ndarray_1d: ",empty_ndarray_1d)
empty_ndarray_1d: [4.94065646e-324 4.94065646e-324 0.00000000e+000 0.00000000e+000
1.32373351e+079]
Ein zweidimensionales Array
import numpy as np
empty_ndarray_2d = np.empty((2,3))
print("empty_ndarray_2d: ",empty_ndarray_2d)
empty_ndarray_2d: [[0. 0. 0.]
[0. 0. 0.]]
1-dimensionales Array
import numpy as np
specified_value = 10
array_size = 5
specified_value_ndarray = np.empty(array_size)
specified_value_ndarray.fill(specified_value)
print("specified_value_ndarray: ",specified_value_ndarray)
specified_value_ndarray: [10. 10. 10. 10. 10.]
Ein zweidimensionales Array
import numpy as np
specified_value = 3
array_size = (2,3)
specified_value_ndarray = np.empty(array_size)
specified_value_ndarray.fill(specified_value)
print("specified_value_ndarray: ",specified_value_ndarray)
specified_value_ndarray: [[3. 3. 3.]
[3. 3. 3.]]
1-dimensionales Array
start_num = 1
end_num = 10
difference = 1
arithmetic_sequence_ndarray = np.array(range(start_num, end_num + 1, difference))
print("arithmetic sequence ndarray: ",arithmetic_sequence_ndarray)
Recommended Posts