{ "cells": [ { "cell_type": "markdown", "id": "e16c6f29", "metadata": {}, "source": [ "# Indizierung und Slicing\n", "\n", "Indizierung ist die Auswahl einer Teilmenge eurer Daten oder einzelner Elemente. In eindimensionalen Arrays ist das sehr einfach; verhalten sie sich doch ähnlich wie Python-Listen:" ] }, { "cell_type": "code", "execution_count": 1, "id": "7eed4014", "metadata": { "execution": { "iopub.execute_input": "2026-05-21T17:13:00.857844Z", "iopub.status.busy": "2026-05-21T17:13:00.857736Z", "iopub.status.idle": "2026-05-21T17:13:00.889953Z", "shell.execute_reply": "2026-05-21T17:13:00.889633Z", "shell.execute_reply.started": "2026-05-21T17:13:00.857829Z" } }, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "id": "8d71c545", "metadata": { "execution": { "iopub.execute_input": "2026-05-21T17:13:00.890409Z", "iopub.status.busy": "2026-05-21T17:13:00.890290Z", "iopub.status.idle": "2026-05-21T17:13:00.900655Z", "shell.execute_reply": "2026-05-21T17:13:00.900397Z", "shell.execute_reply.started": "2026-05-21T17:13:00.890400Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[ 1.55088682, -0.19252388, -0.41198448],\n", " [-0.85917748, -0.62768546, 1.21933903],\n", " [ 0.8389391 , -0.88456804, -0.67016679],\n", " [-1.70774438, -0.78328505, 0.37689532]])" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rng = np.random.default_rng()\n", "data = rng.normal(size=(4, 3))\n", "data" ] }, { "cell_type": "code", "execution_count": 3, "id": "4202c561", "metadata": { "execution": { "iopub.execute_input": "2026-05-21T17:13:00.901444Z", "iopub.status.busy": "2026-05-21T17:13:00.901139Z", "iopub.status.idle": "2026-05-21T17:13:00.903764Z", "shell.execute_reply": "2026-05-21T17:13:00.903499Z", "shell.execute_reply.started": "2026-05-21T17:13:00.901432Z" } }, "outputs": [ { "data": { "text/plain": [ "array([-1.70774438, -0.78328505, 0.37689532])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data[3]" ] }, { "cell_type": "code", "execution_count": 4, "id": "23ee62b6", "metadata": { "execution": { "iopub.execute_input": "2026-05-21T17:13:00.904279Z", "iopub.status.busy": "2026-05-21T17:13:00.904192Z", "iopub.status.idle": "2026-05-21T17:13:00.906672Z", "shell.execute_reply": "2026-05-21T17:13:00.906449Z", "shell.execute_reply.started": "2026-05-21T17:13:00.904270Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[-0.85917748, -0.62768546, 1.21933903],\n", " [ 0.8389391 , -0.88456804, -0.67016679]])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data[1:3]" ] }, { "cell_type": "code", "execution_count": 5, "id": "11a26b4b", "metadata": { "execution": { "iopub.execute_input": "2026-05-21T17:13:00.907009Z", "iopub.status.busy": "2026-05-21T17:13:00.906941Z", "iopub.status.idle": "2026-05-21T17:13:00.908662Z", "shell.execute_reply": "2026-05-21T17:13:00.908454Z", "shell.execute_reply.started": "2026-05-21T17:13:00.907001Z" } }, "outputs": [], "source": [ "data[1:3] = rng.normal(size=(2, 3))" ] }, { "cell_type": "code", "execution_count": 6, "id": "78f018d3", "metadata": { "execution": { "iopub.execute_input": "2026-05-21T17:13:00.911107Z", "iopub.status.busy": "2026-05-21T17:13:00.910773Z", "iopub.status.idle": "2026-05-21T17:13:00.913387Z", "shell.execute_reply": "2026-05-21T17:13:00.913102Z", "shell.execute_reply.started": "2026-05-21T17:13:00.911097Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[ 1.55088682, -0.19252388, -0.41198448],\n", " [ 1.06439017, -0.68654884, 1.1958988 ],\n", " [ 0.22420899, -0.09198245, -0.1812715 ],\n", " [-1.70774438, -0.78328505, 0.37689532]])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data" ] }, { "cell_type": "markdown", "id": "ab9427bb", "metadata": {}, "source": [ "