Curiosity Meets Code

Curiosity Meets Code

Building xsNumPy to Learn NumPy

As developers, researchers, and enthusiasts, we often rely on sophisticated tools to solve problems — but how often do we pause to wonder how these tools are built? This question sparked my journey into creating xsNumPy, a minimalist reimplementation of NumPy only using Python’s standard library.

What began as a curiosity-driven exploration has now evolved into a project that not only deepened my understanding of computational libraries but also serves as a learning tool for others who share the same inquisitiveness. Today, I am thrilled to share xsNumPy — a small pet project that mirrors my passion for learning, teaching, and simplifying complex concepts.

How it All Started

My motivation for xsNumPy was simple yet profound: I wanted to uncover the inner workings of NumPy, a library I admired for its elegance, versatility, and efficiency. As someone deeply engaged in computational projects, I recognized that mastering NumPy required more than just using it — it demanded a granular understanding of its core principles. Thus, xsNumPy became my vehicle for learning by doing.

What is xsNumPy?

xsNumPy is a lightweight implementation of core NumPy features, built entirely with Python’s standard library. Its focus is on simplicity and education, making it an excellent tool for learning and experimentation. It breaks down complex operations into digestible components, making it easier to demonstrate principles like broadcasting**, matrix arithmetic, and vectorized operations.

To put it simply, below would be the core features:

  • Python-First Implementation. Built without dependencies, highlighting Python’s native capabilities.
  • Lightweight Array Object. Support for basic numerical operations like addition, subtraction, scalar multiplication, and dot products.
  • Educational Emphasis. Comprehensive documentation and examples that explain how the library works and compare its features with NumPy.

A Quick and Cheeky Demonstration

Here are some examples of what you can currently do with xsNumPy and lot more:

  • Creating Arrays

>>> import xsnumpy as xp
>>>
>>> xp.array([[1, 2, 3], [4, 5, 6]])
array([[1, 2, 3],
       [4, 5, 6]])
>>> xp.arange(0, 5, 0.5)
array([0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5])
>>> xp.array([1, 2, 3], dtype=xp.bool)
array([True, True, True])
>>> xp.identity(3)
array([[1. , 0. , 0. ],
       [0. , 1. , 0. ],
       [0. , 0. , 1. ]])        

  • Element-wise Operations

>>> a = xp.array([[1, 0], [0, 1]])
>>> b = xp.array([[4, 1], [2, 2]])
>>>
>>> a + b
array([[5, 1],
       [2, 3]])
>>> a @ b
array([[4, 1],
       [2, 2]])
>>> a >= b
array([[False, False],
       [False, False]])        

  • Reshaping and more

>>> x = xp.array([1, 2, 3, 4])
>>> x.shape
(4,)
>>> y = xp.zeros((2, 3, 4))
>>> y.shape
(2, 3, 4)
>>> y.shape = (3, 8)
>>> y
array([[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
       [0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
       [0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ]])        

A Personal Reflection

Building xsNumPy has been a journey of discovery. The last two months have taught me not only about the intricacies of numerical computing but also the importance of craftsmanship in software development. I’ve gained a deeper appreciation for the thoughtfulness behind NumPy’s API, and this project has sharpened my problem-solving and design skills.

What's next?

While xsNumPy is already functional, there’s so much more to explore:

  1. Expanding support for higher dimensional broadcasting. Currently, it supports broadcasting operations up to 2 dimensions.
  2. Adding support for more NumPy native APIs like tanh, relu, etc.


Whether you’re looking for a learning tool or eager to understand numerical computing, or a developer with a passion for low-level systems, I invite you to explore xsNumPy.

Check out the GitHub repository and start experimenting today.

Jennifer Sanchez Lugo

Actuarial Science Student at DePaul University | Operations Associate at Rite Portable Restrooms

2 个月

Great work Akshay!! ????

要查看或添加评论,请登录

Akshay Mestry的更多文章

  • From Loss to Gratitude...

    From Loss to Gratitude...

    For those who all are reading this, I'd like to thank you for taking your time. Ever since last week, I wanted to write…

    1 条评论
  • Embracing Open Science with NASA's TOPS Initiative!

    Embracing Open Science with NASA's TOPS Initiative!

    Over the years, a lot of people that I've interacted with especially students and even experienced professionals have…

    2 条评论
  • Advancing Open Science with NASA’s TOPST SCHOOL Initiative ??

    Advancing Open Science with NASA’s TOPST SCHOOL Initiative ??

    I'm incredibly excited to share a significant milestone in my professional as well as academic journey — one that…

    4 条评论
  • ?? My Experience with NASA's TOPS! ??

    ?? My Experience with NASA's TOPS! ??

    Last month, I embarked on an extraordinary journey with NASA's Transform to Open Science (TOPS) 101 workshop at…

    5 条评论

社区洞察

其他会员也浏览了