0Pricing
Mojo Academy · Lektion

NumPy aus Mojo verwenden

Rufen Sie NumPy-Arrays und -Funktionen auf.

NumPy aus Mojo verwenden ist eine kostenlose Mojo Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Mojo Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Mojo Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

NumPy, From Mojo

NumPy powers most Python number-crunching, and Mojo lets you call it directly, so you keep that ecosystem while writing fast code. 🔢

Import It First

Bring NumPy in the same way you import any Python module: call Python.import_module with the name "numpy".

var np = Python.import_module("numpy")

Make an Array

With the handle in hand, call NumPy functions through dot access. Here you build an array from a Python list of numbers.

var a = np.array([1, 2, 3])

Use Array Functions

Every NumPy creator works: np.zeros and np.ones build filled arrays, perfect for setting up buffers before computation.

var z = np.zeros(5)

Math on Arrays

Call NumPy math functions just like in Python. np.sum adds every element of an array and hands back the total.

var total = np.sum(a)

Whole-Array Ops

NumPy shines at vectorized math: one call like np.sqrt works on the entire array at once, no manual loop needed.

var roots = np.sqrt(a)

Reading Shape

Access an array's attributes through dot syntax. The shape attribute tells you the dimensions of your array.

var dims = a.shape

It May Raise

Calls across the bridge can fail, so NumPy work belongs in a function marked raises to handle any error cleanly.

fn run() raises:
    var np = Python.import_module("numpy")

Same API You Know

The NumPy API is identical to Python's: if you know np.linspace or np.dot, you already know how to call them from Mojo.

var grid = np.linspace(0, 1, 10)

Build, Then Use

A common pattern is to create an array, then reshape it. np.reshape reorganizes the same data into new dimensions for you.

var m = np.reshape(a, (3, 1))

Best of Both

You get NumPy's mature, battle-tested routines while orchestrating them from Mojo, blending convenience with Mojo's performance mindset. ⚡

Quick Check

Recall how you start using NumPy inside a Mojo program.

Recap

You imported NumPy with Python.import_module, then built arrays and ran vectorized math using the very same API you know from Python. 🎯

Häufig gestellte Fragen

Ist die Lektion „NumPy aus Mojo verwenden“ kostenlos?

Ja — der vollständige Text von „NumPy aus Mojo verwenden“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Mojo Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Mojo Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „NumPy aus Mojo verwenden“?

Rufen Sie NumPy-Arrays und -Funktionen auf. Du übst Mojo Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Mojo Academy zu starten?

Keine Vorkenntnisse erforderlich. Mojo Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.

Wie lange dauert die Lektion „NumPy aus Mojo verwenden“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Mojo Academy-Lektion Code schreiben und ausführen?

Ja. Jede Mojo Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. NumPy aus Mojo verwenden
  2. Mojo-Daten an Python übergeben
  3. Python-Objekte zurücklesen
  4. Tücken der Interop-Performance
← Zurück zu Mojo Academy