运行以下命令时:
def batch_generator(batch_size, sequence_length):
'''Generator function for creating random batches of training-data.'''
# Infinite loop.
while True:
# Allocate a new array for the batch of input-signals.
x_shape = (batch_size, sequence_length, num_x_signals)
x_batch = np.zeros(shape=x_shape, dtype=np.float16)
# Allocate a new array for the batch of output-signals.
y_shape = (batch_size, sequence_length, num_y_signals)
y_batch = np.zeros(shape=y_shape, dtype=np.float16)
# Fill the batch with random sequences of data.
for i in range(batch_size):
# Get a random start-index.
# This points somewhere into the training-data.
idx = np.random.randint(num_train - sequence_length)
# Copy the sequences of data starting at this index.
x_batch[i] = x_train_scaled[idx:idx+sequence_length]
y_batch[i] = y_train_scaled[idx:idx+sequence_length]
yield (x_batch, y_batch)
batch_size = 256
sequence_length = 2 * 7 * 8
generator = batch_generator(batch_size=batch_size,
sequence_length=2 * 7 * 8)
x_batch, y_batch = next(generator)
此代码块返回 ValueError: high <= 0
这是我收到的错误:
ValueError Traceback (最近一次调用最后) ~\AppData\Local\Temp/ipykernel_11424/2071659211.py in ----> 1 x_batch, y_batch = next(generator)
~\AppData\Local\Temp/ipykernel_11424/1112051746.py in batch_generator(batch_size, sequence_length) 18 # Get a random start-index. 19 # This points somewhere into the training-data. ---> 20 idx = np.random.randint(num_train - sequence_length) 21 22 # Copy the sequences of data starting at this index.
mtrand.pyx in numpy.random.mtrand.RandomState.randint()
_bounded_integers.pyx in numpy.random._bounded_integers._rand_int32()
ValueError: high <= 0
I think I'm late, but nevertheless
ValueError: high <= 0
It happens because here:
idx = np.random.randint(num_train - sequence_length)
You input one argument instead two.
I think it can be useful: https://numpy.org/doc/stable/reference/random/generated/numpy.random.randint.html
最有可能的是,num_train <= sequence_length
导致零值或负值作为参数传递给行中randint()
的idx = np.random.randint(num_train - sequence_length)
ValueError: high <= 0
randint()
当使用单个参数时,当 的参数为 0 或负数时发生。