Python-Memorandum

Dieser Artikel ist eine Aufzeichnung des Lernens für Python-Anfänger. Ich schreibe hauptsächlich, was ich nicht verstanden habe. Die Reihenfolge ist also chaotisch. Als Referenz ,,,

NumPy np.array

# -*- coding: utf-8 -*-
import numpy as np

#Deklaration / Initialisierung des 2D-Arrays
A = np.array([[1, 2],
              [3, 4],
              [5, 6]])

#Matrixgröße
print("Die Größe der Matrix A.:", A.shape)
print("Anzahl der Zeilen in Matrix A.:", A.shape[0])
print("Anzahl der Spalten in Matrix A.:", A.shape[1])

"""
Die Größe der Matrix A.:(3, 2)
Anzahl der Zeilen in Matrix A.:3
Anzahl der Spalten in Matrix A.:2
"""

np.reshape Form [0] zeigt ** Anzahl der Zeilen ** an, Form [1] zeigt ** Anzahl der Spalten ** an.

import numpy as np

a = np.arange(24)

print(a)
# [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23]

print(a.shape)
# (24,)

print(a.ndim)
# 1

a_4_6 = a.reshape([4, 6])

print(a_4_6)
# [[ 0  1  2  3  4  5]
#  [ 6  7  8  9 10 11]
#  [12 13 14 15 16 17]
#  [18 19 20 21 22 23]]

print(a_4_6.shape)
# (4, 6)

print(a_4_6.ndim)
# 2

In np.ndim finden Sie leicht die Anzahl der Elemente. Umformen entspricht dem obigen Code.

[:, 0] Alle 0. Spalte. Wenn es sich um ein 2x2-Array handelt, ist es ein [0: 2, 0], wenn es ohne Auslassung geschrieben wird. A [a: b, c: d] bedeutet, Spalten von c nach d (ohne b und d) in den Zeilen von a nach b zu extrahieren.

np.where

import numpy as np

a = np.arange(9).reshape((3, 3))
print(a)
# [[0 1 2]
#  [3 4 5]
#  [6 7 8]]

print(np.where(a < 4, -1, 100))
# [[ -1  -1  -1]
#  [ -1 100 100]
#  [100 100 100]]

print(np.where(a < 4, True, False))
# [[ True  True  True]
#  [ True False False]
#  [False False False]]

print(a < 4)
# [[ True  True  True]
#  [ True False False]
#  [False False False]]

Wenn das Folgende nur eine Bedingung ist, wird wahr oder falsch angezeigt.

np.hstack

Konsolidierung von Arrays mit der gleichen Anzahl von Spalten. Für Zeilen np.vstack.

np.unique()

In der Sequenz in () ohne Nebel extrahieren.

import numpy as np

a = np.array([0, 0, 30, 10, 10, 20])
print(a)
# [ 0  0 30 10 10 20]

print(np.unique(a))
# [ 0 10 20 30]

print(type(np.unique(a)))
# <class 'numpy.ndarray'>

Recommended Posts

Python-Memorandum 2
Python-Memorandum
Python Memorandum
Python Memorandum
Python Memorandum
Python-Memorandum
Python-Grundmemorandum
Python Pathlib Memorandum
Python-Memorandum (Algorithmus)
Python-Memorandum [Links]
Python-Memorandum-Nummerierungsvariablen
Python Memorandum (sequentielle Aktualisierung)
Python
Python-Memorandum (persönliches Lesezeichen)
Python Basic Memorandum Teil 2
Memorandum @ Python ODER Seminar
Python Memorandum Super Basic
Cisco Memorandum _ Eingabekonfiguration mit Python
ABC-Memorandum [ABC163 C --managementr] (Python)
Python-Anfänger-Memorandum-Funktion
Memorandum @ Python ODER Seminar: matplotlib
[Python] Memorandum zur Vermeidung von SQLAlchemy-Fehlern
Memorandum über Korrelation [Python]
Memorandum @ Python ODER Seminar: Pulp
Ein Memorandum über den Python-Mock
Memorandum @ Python ODER Seminar: Pandas
[Python] Memorandum über zufällige Generationen
Memorandum @ Python ODER Seminar: Scikit-Learn
Python-Memorandum zur parallelen / asynchronen Ausführung
Matplotlib Memorandum
Kafka Python
Linux Memorandum
Python-Zusammenfassung
Eingebaute Python
ABC-Memorandum [ABC159 C - Maximales Volumen] (Python)
jinja2 Memorandum
Python-Einschlussnotation
Python-Technik
Python pywin32 (win32com) Excel-Memorandum
Python studieren
Python 2.7 Countdown
Django Memorandum
Python FlowFishMaster
Python-Dienst
Python-Tipps
Python-Funktion ①
Python-Grundlagen
Python-Memo