r/Numpy • • May 24 '26

Relaunch of r/numpy

35 Upvotes

Hi, Im the new moderator here at r/numpy. I'm a data scientist and product manager for analytics and fintech products. I've been doing that a little over 30 years now.

I'm not new to moderating. I'm one of the moderators at r/software and have helped out in a number of other communities as well. Having said that, we can all learn more - me included, so I hope you can help contribute as well.

I would love to see this community be a place where people can get inspiration and help in their mathematical development projects.

If you've got ideas about how to grow and manage this community, please let me know.


r/Numpy • • May 27 '20

Numpy Cheatsheet

Post image
33 Upvotes

r/Numpy • • May 10 '20

Numpy array is the worst part of python.

24 Upvotes

I come from HPC (c++/c/Fortran, etc), I can read and use other languages without issue. I like many parts of python, and its nice a lot of the time to not have to program everything from the ground up. I am not the biggest fan of weakly typed languages and python is slow, but it defiantly has a place and it does what it's designed to do pretty well.

However, the way numpy organises its array syntax and the general working of array is probably the most confusing poorly designed thing in the entire language, perhaps in the world of programming languages. I spend 80% of my programming time trying to get things into the right shape or work out what shape they are, and then use the correct functions to do extremely trivial appends/inserts/delete etc. Its is vague and honestly should be rewritten. There is honestly no defence of this poor syntax. There is a reason pretty much every other language deals with arrays in the same way... it makes sense.

I know that the hardcore python fanboys will tell me I am not doing things correctly, or lol, say "I must think 'pythonically'". BS, a good language does not need some gibberish word to defend the poor design.


r/Numpy • • Jul 11 '20

Help us to make NumPy better!

21 Upvotes

Yes, it’s a survey. But it’s very important.

Having limited human and financial resources is a common challenge for open source projects. NumPy is not an exception. Your responses will help the NumPy leadership team to better guide and prioritize decision-making about the development of NumPy as software and a community.

What started as a humble project by a dedicated core of user-developers has since transformed into a foundational component of the widely-adopted scientific Python ecosystem used by millions worldwide. To engage non-English speaking stakeholders, the inaugural NumPy community survey is offered in 8 additional languages: Bangla, French, Hindi, Japanese, Mandarin, Portuguese, Russian, and Spanish.

Follow the link to get started: NumPy Community Survey 2020.


r/Numpy • • Apr 25 '26

Numpy es increible!

Post image
17 Upvotes

He estado haciendo unas pruebas de eficiencia y Numpy es considerablemente mas rapido que python puro (para sorpresa de nadie). Yo soy bastante nuevo en esto, por eso me ha parecido muy interesante.

El grafico de una prueba entre estas dos funciones:

def python_meth(nums: list[int]):
    return [x**2 for x in nums]


def numpy_meth(nums: np.ndarray):
    return nums**2

r/Numpy • • Jun 08 '22

This Python cheat sheet is a quick reference for NumPy beginners.

Post image
14 Upvotes

r/Numpy • • Oct 07 '26

How do you guys keep track of tensor shapes?

Thumbnail
gallery
11 Upvotes

Lately, I've been getting frustrated by tensor shape runtime errors. I tried adding shape comments, but I find them verbose and hard to maintain when my code changes constantly.

I looked around for tools like Pyrefly's experimental shape tracking, which I still find verbose (1st image). Since I couldn't find my tool, I ended up buidling a small open-source static analyzer (2nd image).

How do you handle these issues? Any tools you can recommend?


r/Numpy • • 16d ago

I'm releasing Numstore finally!

10 Upvotes

https://github.com/lincketheo/Numstore/

Numstore is a single file database for arrays. I started it because I was never able to use a database for high dimensional numerical data, and I wanted something I could actually use for that.

The core is written in C, but you don't need to write any C to use it. Pynumstore is now the primary way to use Numstore.

It's a personal open source project. I don't make any money from it. It's me giving back to the scientific community.


r/Numpy • • Feb 02 '26

Learn NumPy indexing with our game: NumPy Ducky

9 Upvotes

If you are a beginner and want understand NumPy indexing, slicing and dimensionality, give our game a try! In the game you will help ducks get into water by writing NumPy code, similar to the legendary Flexbox Froggy.

Repo: https://github.com/0stam/numpy-ducky
Download: https://github.com/0stam/numpy-ducky/releases

The game allows you to see a visual result of your code, which should make it easier to understand and correct your mistakes.

We made the game as a university project, so the scope is not huge, but we'd love you hear some real user feedback. If it helps you wrap your head around arrays (or if you just like ducks), consider dropping a star (:


r/Numpy • • Jun 16 '24

Numpy 2.0 released

9 Upvotes

Release notes here: https://github.com/numpy/numpy/releases/tag/v2.0.0

Get it here: https://pypi.org/project/numpy

CAUTION: Numpy 2.0 has breaking changes and not all packages that depend on numpy have been upgraded yet. I recommend installing it in a virtual environment first if your Python environment usually has the latest and greatest.


r/Numpy • • Mar 02 '22

Speed up Python code that uses NumPy

8 Upvotes

A useful article about how array contiguity can have a big impact on code execution time.

Join our Slack community where we enjoy discussion of topics like this one.NumPy is the most popular Python module. It is popular for its N-dimensional array structure and suite of tools that can be used to create, modify, and process them. It also serves as the backbone for data structures provided by other popular modules including Pandas DataFrames, TensorFlow tensors, PyTorch tensors, and many others. Additionally, NumPy is written largely in C, which results in code that runs faster than traditional Python.

What if there were a simple way to find out if your Python code that uses NumPy could be sped up even further? Fortunately, there is!

ndarrays​

NumPy, like everything else, stores its data in memory. When a NumPy ndarray is written to memory, its contents are stored in row-major order by default. That is, elements in the same row are adjacent to one another in memory. This order is known as C contiguous, since it's how arrays are stored in memory by default in C.

import numpy as np  x = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])  print(x)  print(x.flags['C_CONTIGUOUS']) 

In this case, each element of xis adjacent to its row neighbors in memory. Since memory can be visualized as a flat buffer.

That's straightforward enough. But did you know that you can set the contiguity of a NumPy array yourself? The other common contiguity is known as F contiguous, since it's how arrays are stored in memory by default in Fortran.

import numpy as np y = np.asfortranarray(x) print(x.flags['F_CONTIGUOUS']) 

In this case, each element of y is adjacent to its column-wise neighbors in memory.

Examples​

But what difference does the storage method make in terms of your Python code? It turns out that it can make a significant difference in terms of speed, depending on the dimensions of your data and the operations you want to perform. Code execution time decreases as values in memory get closer together.

Let's explore this with some simple examples.

import numpy as np
import time
row_major_array = np.random.uniform(0, 1, (10000, 2))
col_major_array = np.asfortranarray(np.array(row_major_array, copy = True))

print(row_major_array.flags['C_CONTIGUOUS'])
print(col_major_array.flags['F_CONTIGUOUS'])

start = time.time()
for i in range(1000):
    row_major_sum_along_rows = np.sum(row_major_array, axis = 0)
    row_major_sum_along_columns = np.sum(row_major_array, axis = 1)
end = time.time()
row_major_elapsed = (end - start) / 1000

start = time.time()
for i in range(1000):
    col_major_sum_along_rows = np.sum(col_major_array, axis = 0)
    col_major_sum_along_columns = np.sum(col_major_array, axis = 1)
end = time.time()
col_major_elapsed = (end - start) / 1000

print(f"Col major average time: {col_major_elapsed*1000} milli seconds.")

LOG:

True 
True 
Row major average time: 0.2994 milli seconds. 
Col major average time: 0.02221 milli seconds.

We construct row_major_array and col_major_array , which are each two-dimensional arrays with 2 columns and 10,000 rows of random data between 0 and 1. The contiguity of the arrays are set in accordance with their naming. Then, the column-wise and row-wise sums are computed. We perform each of the two summations 1,000 times and time it, then divide the total time elapsed by 1,000 to see what the average computation time is.

Here, column major order is faster than row major order. The memory ordering of col_major_arrayis such that the distance between subsequent values needed for the summations is much smaller on average. This difference is significant. Let's try a similar operation on an array with far more rows than columns.

import numpy as np
import time
row_major_array = np.random.uniform(0, 1, (2, 10000))
col_major_array = np.asfortranarray(np.array(row_major_array, copy = True))

print(row_major_array.flags['C_CONTIGUOUS'])
print(col_major_array.flags['F_CONTIGUOUS'])

start = time.time()
for i in range(1000):
    row_major_sum_along_rows = np.sum(row_major_array, axis = 0)
    row_major_sum_along_columns = np.sum(row_major_array, axis = 1)
end = time.time()
row_major_elapsed = (end - start) / 1000

start = time.time()
for i in range(1000):
    col_major_sum_along_rows = np.sum(col_major_array, axis = 0)
    col_major_sum_along_columns = np.sum(col_major_array, axis = 1)
end = time.time()
col_major_elapsed = (end - start) / 1000

print(f"Row major average time: {row_major_elapsed*1000} milli seconds.")
print(f"Col major average time: {col_major_elapsed*1000} milli seconds.")

LOG:

True 
True
Row major average time: 0.03357 milli seconds. 
Col major average time: 0.28725 milli seconds.

This time around, each array has 2 columns and 10,000 rows. The same two summations are performed. Unsurprisingly, the performance difference is approximately equal but opposite to our first example. This time around, the row major order performs better than column major due to the smaller memory distance traveled to fetch required values.

For Python applications that deal with relatively small historical data, these speed differences will not make a major difference in performance. But if you deal with sufficiently large datasets, or high volumes of data coming in real-time, these speed differences can have a huge impact. In both of the presented examples, array contiguity is solely responsible for an approximately 10x difference in speed. These are toy problems; the actual performance differences will vary from application to application. NumPy does give you the ability to specify array contiguity for a reason, though!

If there are other ways you speed up your Python code that uses NumPy, we'd love to hear about it.


r/Numpy • • Jan 05 '21

How to tell when numpy function is optimized via parallelization and when mpi4py is needed?

8 Upvotes

As the title suggests:

How do I know when I need to optimize a numpy function/routine via mpi4py?

For example: numpy.correlate()

Is this processed optimized and using the full parallelized processing power on my computer or cluster?

Or do I need to make my own correlation function that is parallelized via mpi4py?

When I call this function and look at my task manager on windows10 it clearly shows all my CPUs initiating so my guess would be that it already has been optimized and there's no point in writing my own mpi4py function for it.


r/Numpy • • Aug 18 '20

[Article] How to use NumPy to optimize your code: understanding NumPy Internals, Strides, Reshape and Transpose

8 Upvotes

NumPy can make your code run faster than you might realize--a particularly useful hack for long-running data science/ML projects, for instance. This post covers common mistakes that lead to unnecessary data copying and memory allocation, as well as how to use NumPy internals, strides, reshaping and transpose to optimize your Python code.

Article link: https://blog.paperspace.com/numpy-optimization-internals-strides-reshape-transpose/


r/Numpy • • Sep 14 '26

Starting out in Numpy. Asking for Tips and advice.

7 Upvotes

I'm starting out in Numpy, I dont have a teacher nor do i have a curriculum to follow.

Im ultimately learning for data science and ML.

How would you go about learning if there was no one to teach you?

I know i can pay for a course and surely have it down easily, i mean its like 39$ for the one im looking at, but for some reason i have a pull to challenge myself. Some how it doesn't feel right having it laid down this time.

I think i might also teach myself the pd, plt, and maybe sp.

What is your opinion of my stand point? Have you felt the same way at some point or maybe you think it's pointless? Let me know, thanks.


r/Numpy • • Jun 06 '26

Adding Numpy to LibreOffice

7 Upvotes

Hi all,

I've been working on a FOSS LibreOffice extension called WriterAgent, but which also has Calc/Python features.

I recently added Numpy support to the plugin. I wrote about the dev process: https://keithcu.com/wordpress/?p=5310 It's tricky because LibreOffice ships with a Python interpreter for many OSes so you can't just import numpy. I had to do everything cross-process, but it works and is fast enough.

The plugin has many AI features (chat with document, background grammar checker etc.) but you don't have to use any of it. It registers a =Python() function, and has other scripting, TeX, etc. capabilities that work without the AI. The slop is 100% optional!

I started adding Python features to expose it to the LLMs, but decided to support it for us meatbags also 😉. I'm proud of the features so far, auto-imports, a special data parameter that supports multiple ranges, auto infer result, shared init scripts, an optional shared kernel between cells, shared code cells which can be called from other places, sandboxing, high-speed IPC and color syntax. The Excel xl("A100") design breaks recalc and is a total hack.

I've sent a couple of emails to the LibreOffice-dev team about early versions of this feature, and how they probably should have added it years ago, but with the Collabora drama, the community is currently split so I've not seen any feedback yet. Please let me know if you have any ideas, or try it out and find bugs, etc.

Thank you for reading,

-Keith


r/Numpy • • Feb 21 '26

NumPy requires machine to support X86_V2

7 Upvotes

Recently I installed pandas 3.0.0 that ships with NumPy 2.4.2 (released Feb 2026), on a computer from around 2008. Its CPU apparently has what is now called microlevel architecture x86-64-v1.
When running a Python program that imports pandas the following error appears:
File "<removed-path-for-this-post>/lib/python3.12/site-packages/numpy/_core/multiarray.py", line 11, in <module>
from . import _multiarray_umath, overrides
RuntimeError: NumPy was built with baseline optimizations:
(X86_V2) but your machine doesn't support:
(X86_V2).

When manually importing NumPy 2.3.5 (released Nov 2025) instead of 2.4.2, the program runs successfully.

Questions:

  • Have more people reading this post run into this issue?

  • Provided that compiling NumPy myself is too much hassle: Does anyone know if it is to be expected that from now on, with each installation of pandas I need to manually downgrade the NumPy version on this computer?


r/Numpy • • Aug 20 '25

Numpy resource for data science

7 Upvotes

I am currently learning python for data science. I have completed the basics and data structures. I want to go for libraries. Could you suggest some good and free resources to learn numpy for DS.


r/Numpy • • Nov 14 '21

Is NumPy fully compatible with M1 Mac now?

7 Upvotes

r/Numpy • • Oct 30 '21

Are triangular matrices more efficient in Numpy?

7 Upvotes

I am calculating distances between, for instance, atoms (for MD simulations). Since the matrix is symmetric, I might as well turn it into a triangular matrix.

  1. However, is Numpy more efficient when handling triangular matrices (those with elements below the diagonal set to zero)? Particularly, operations like squaring, sum, square roots etc.

  2. Does Numpy even know that it is handling a triangular matrix?

  3. How do I make it recognize triangular matrices, if there is such functionality?

I'm not sure about this post (I don't understand it ;)

https://stackoverflow.com/questions/50907049/how-to-make-np-where-more-efficient-with-triangular-matrices

Also, I read that there are triangular matrices in Scipy. Maybe that would help?

https://faculty.math.illinois.edu/~hirani/cbmg/linalg1.html

https://gist.github.com/kylebgorman/8064310

Thanks in advance!


r/Numpy • • Dec 22 '20

NumPy Illustrated: The Visual Guide to NumPy

Thumbnail
medium.com
7 Upvotes

r/Numpy • • Oct 20 '20

Working Between OpenCV and NumPy Coordinate Systems for Image Processing

Thumbnail
lionbridge.ai
7 Upvotes

r/Numpy • • Sep 17 '20

Can we change the logo to the new one?

7 Upvotes

The new NumPy logo is out, and it would be nice to have the new look here, too :)

https://github.com/numpy/numpy/blob/master/branding/logo/logoguidelines.md


r/Numpy • • Aug 10 '20

[Article] How to use NumPy to optimize your code: vectorization and broadcasting

7 Upvotes

NumPy can make your code run faster than you might realize--a particularly useful hack for long-running data science/ML projects. This post analyzes why loops are so slow in Python, and how to replace them with vectorized code using NumPy. We'll also cover in-depth how broadcasting in NumPy works, along with a few practical examples. Ultimately we'll show how both concepts can give significant performance boosts for your Python code.

Article link: https://blog.paperspace.com/numpy-optimization-vectorization-and-broadcasting/


r/Numpy • • Jul 11 '25

How NumPy works

6 Upvotes

You may know how to use numpy but do you know how it works? If you're interested in knowing, I made this video to explain it https://www.youtube.com/watch?v=Qhkskqxe4Wk


r/Numpy • • Jul 05 '24

I Found a list of Best Free Numpy courses! Sharing with you guys.

6 Upvotes

Some of the best resources to learn Numpy.