LoslegenKostenlos loslegen

Generating a sequence of numbers

You may want to create an array of a range of numbers (e.g., 1 to 10) without having to type in every single number. The NumPy function arange() is an efficient way to create numeric arrays of a range of numbers. The arguments for arange() include the start, stop, and step interval as shown below:

np.arange(start, stop, step)

numpy is imported as np.

Diese Übung ist Teil des Kurses

Introduction to Python for Finance

Kurs anzeigen

Anleitung zur Übung

  • Create an array company_ids containing the numbers 1 through 7 (inclusive).
  • Create an array company_ids_odd containing only the odd numbers from 1 through 7 (inclusive).

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Create and print company IDs
company_ids = np.arange(____, ____, 1)
print(company_ids)

# Use array slicing to select specific company IDs
company_ids_odd = ____(1, ____, ___)
print(company_ids_odd)
Code bearbeiten und ausführen