Mojo-Numerics-and-Algorithms-group / NuMojo

NuMojo is a library for numerical computing in Mojo 🔥 similar to numpy in Python.
Apache License 2.0
86 stars 15 forks source link

Update `to_numpy` function so that multiple data types are allowed. #49

Closed forFudan closed 2 months ago

forFudan commented 2 months ago

Update to_numpy function so that multiple data types are allowed.

Example:

import numojo as nm
from python import Python

fn main() raises:
    var array = nm.NDArray[nm.i32](1000,1000,random=True)
    print(array.to_numpy())

float64:

[[0.085  0.8916 0.1897 ... 0.5549 0.2582 0.0078]
 [0.8286 0.6087 0.1889 ... 0.8907 0.6361 0.82  ]
 [0.6088 0.0533 0.7494 ... 0.0336 0.7792 0.7019]
 ...
 [0.7376 0.4745 0.6004 ... 0.1094 0.8473 0.231 ]
 [0.3293 0.7703 0.4481 ... 0.1036 0.252  0.1913]
 [0.8816 0.6159 0.8896 ... 0.5805 0.7877 0.0112]]

int32:

[[ 1015961569 -1622847108  2029044002 ...  -454831891  1704168191
   1437546358]
 [ -520992968 -1055649167  -126675237 ...   -67502823 -1586034558
   -316907984]
 [-1275429598 -1923702087   133396804 ... -1838852486   688436754
  -1148766235]
 ...
 [  826482507  1735843351   885640559 ...   635159423  1318392211
   1438666918]
 [ 1004778054  1109507528  1954911815 ...   175739532 -1995920687
   -585378106]
 [  489140068 -1218268742 -2041196043 ...  -457175955  1927216093
  -1085590885]]