Frage zu Numpy "shape"
Verfasst: Mittwoch 14. Februar 2018, 18:40
Hallo, habe folgendes Verständnisproblem. Ich will aus einem Testdatensatz mehrere Sätze erzeugen. Wenn ich im Code six und siy gleich wähle, dann hat xy das shape (10, 2, six bzw siy) Wenn six und siy verschieden sind, dann zeigt xy das shape (10, 2). Kann mir das bitte jemand erklären??
Vielen Dank und Gruß
Vielen Dank und Gruß
Code: Alles auswählen
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 14 18:09:38 2018
@author: Rainer
"""
import numpy as np
six = 9
siy = 9
x = []
for i in range(10):
m = np.random.randint(1, 30, size=six)
x.append(m)
x = np.array(x)
print("x = ", x)
print("type(x) = ", type(x))
print("x.shape = ", x.shape)
print("x.dtype = ", x.dtype)
print("len(x) = ", len(x))
y = []
for i in range(len(x)):
m = np.random.randint(1, 30, size=siy)
y.append(m)
y = np.array(y)
print("y = ", y)
print("type(y) = ", type(y))
print("y.shape = ", y.shape)
print("y.dtype = ", y.dtype)
print("len(y) = ", len(y))
xy = []
for d in range(len(x)):
a = y[d]
b = x[d]
xy.append([a, b])
xy = np.array(xy)
print("xy = ", xy)
print("type(xy) = ", type(xy))
print("xy.shape = ", xy.shape)
print("xy.dtype = ", xy.dtype)
print("len(xy) = ", len(xy))