In [1]: import numpy as np
In [2]: a = np.array([[2,0],[3,0],[3,1],[5,0],[5,1],[5,2]])
In [3]: b = np.zeros((6,3), dtype='int32')

In [4]: b[a[:,0], a[:,1]] = 10

In [5]: b
Out[5]: 
array([[ 0,  0,  0],
       [ 0,  0,  0],
       [10,  0,  0],
       [10, 10,  0],
       [ 0,  0,  0],
       [10, 10, 10]])

Why it works:

If you index b with two numpy arrays in an assignment,

b[x, y] = z

then think of NumPy as moving simultaneously over each element of x and each element of y and each element of z (let's call them xval, yval and zval), and assigning to b[xval, yval] the value zval. When z is a constant, "moving over z just returns the same value each time.

That's what we want, with x being the first column of a and y being the second column of a. Thus, choose x = a[:, 0], and y = a[:, 1].

b[a[:,0], a[:,1]] = 10

Why b[a] = 10 does not work

When you write b[a], think of NumPy as creating a new array by moving over each element of a, (let's call each one idx) and placing in the new array the value of b[idx] at the location of idx in a.

idx is a value in a. So it is an int32. b is of shape (6,3), so b[idx] is a row of b of shape (3,). For example, when idx is

In [37]: a[1,1]
Out[37]: 0

b[a[1,1]] is

In [38]: b[a[1,1]]
Out[38]: array([0, 0, 0])

So

In [33]: b[a].shape
Out[33]: (6, 2, 3)

So let's repeat: NumPy is creating a new array by moving over each element of a and placing in the new array the value of b[idx] at the location of idx in a. As idx moves over a, an array of shape (6,2) would be created. But since b[idx] is itself of shape (3,), at each location in the (6,2)-shaped array, a (3,)-shaped value is being placed. The result is an array of shape (6,2,3).

Now, when you make an assignment like

b[a] = 10

a temporary array of shape (6,2,3) with values b[a] is created, then the assignment is performed. Since 10 is a constant, this assignment places the value 10 at each location in the (6,2,3)-shaped array. Then the values from the temporary array are reassigned back to b. See reference to docs. Thus the values in the (6,2,3)-shaped array are copied back to the (6,3)-shaped b array. Values overwrite each other. But the main point is you do not obtain the assignments you desire.

Answer from unutbu on Stack Overflow
🌐
NumPy
numpy.org › doc › stable › user › basics.indexing.html
Indexing on ndarrays — NumPy v2.5 Manual
The basic slice syntax is i:j:k where i is the starting index, j is the stopping index, and k is the step (\(k\neq0\)). This selects the m elements (in the corresponding dimension) with index values i, i + k, …, i + (m - 1) k where \(m = q + (r\neq0)\) and q and r are the quotient and remainder ...
🌐
W3Schools
w3schools.com › python › numpy › numpy_array_indexing.asp
NumPy Array Indexing
Think of 2-D arrays like a table with rows and columns, where the dimension represents the row and the index represents the column. Access the element on the first row, second column: import numpy as np arr = np.array([[1,2,3,4,5], [6,7,8,9,10]]) ...
Discussions

Python optimization
🌐 r/Python
25
14
April 1, 2026
using np.where on a 2D array
Do an all-reduction after comparing the two arrays: index_that_matches = np.where((reduced == vector).all(1))[0][0] More on reddit.com
🌐 r/learnpython
3
2
September 5, 2022
Indexing a np.array with another np.array
Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you. I think I have detected some formatting issues with your submission: Python code found in submission text that's not formatted as code. If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting. Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here . More on reddit.com
🌐 r/learnpython
4
1
July 14, 2022
Is it possible to access multidimensional numpy array with a single index without a reshape?
But is there a property or a trick to access the elements with one index without using a reshape? I mean, it's a 2D array. Accessing it via a 1D index is reshaping it. More on reddit.com
🌐 r/learnpython
4
1
June 30, 2023
Top answer
1 of 2
67
In [1]: import numpy as np
In [2]: a = np.array([[2,0],[3,0],[3,1],[5,0],[5,1],[5,2]])
In [3]: b = np.zeros((6,3), dtype='int32')

In [4]: b[a[:,0], a[:,1]] = 10

In [5]: b
Out[5]: 
array([[ 0,  0,  0],
       [ 0,  0,  0],
       [10,  0,  0],
       [10, 10,  0],
       [ 0,  0,  0],
       [10, 10, 10]])

Why it works:

If you index b with two numpy arrays in an assignment,

b[x, y] = z

then think of NumPy as moving simultaneously over each element of x and each element of y and each element of z (let's call them xval, yval and zval), and assigning to b[xval, yval] the value zval. When z is a constant, "moving over z just returns the same value each time.

That's what we want, with x being the first column of a and y being the second column of a. Thus, choose x = a[:, 0], and y = a[:, 1].

b[a[:,0], a[:,1]] = 10

Why b[a] = 10 does not work

When you write b[a], think of NumPy as creating a new array by moving over each element of a, (let's call each one idx) and placing in the new array the value of b[idx] at the location of idx in a.

idx is a value in a. So it is an int32. b is of shape (6,3), so b[idx] is a row of b of shape (3,). For example, when idx is

In [37]: a[1,1]
Out[37]: 0

b[a[1,1]] is

In [38]: b[a[1,1]]
Out[38]: array([0, 0, 0])

So

In [33]: b[a].shape
Out[33]: (6, 2, 3)

So let's repeat: NumPy is creating a new array by moving over each element of a and placing in the new array the value of b[idx] at the location of idx in a. As idx moves over a, an array of shape (6,2) would be created. But since b[idx] is itself of shape (3,), at each location in the (6,2)-shaped array, a (3,)-shaped value is being placed. The result is an array of shape (6,2,3).

Now, when you make an assignment like

b[a] = 10

a temporary array of shape (6,2,3) with values b[a] is created, then the assignment is performed. Since 10 is a constant, this assignment places the value 10 at each location in the (6,2,3)-shaped array. Then the values from the temporary array are reassigned back to b. See reference to docs. Thus the values in the (6,2,3)-shaped array are copied back to the (6,3)-shaped b array. Values overwrite each other. But the main point is you do not obtain the assignments you desire.

2 of 2
4

TL;DR: Use advanced indexing: b[*a.T] = 10

You can also transpose the index array a, convert the result into a tuple and index the array b and assign a value. Converting the index array into a tuple (or unpacking it inside a []) ensures that multidimensional indexing works as expected. This is assignment by advanced indexing.

a = np.array([[2, 0], [3, 0], [3, 1], [5, 0], [5, 1], [5, 2]])
b = np.zeros((6,3), dtype ='int32')

b[*a.T] = 10
# or
b[tuple(a.T)] = 10
# or 
b[(*a.T,)] = 10
# or 
b[(*a.T.tolist(),)] = 10

All of them produce the expected output of

array([[ 0,  0,  0],
       [ 0,  0,  0],
       [10,  0,  0],
       [10, 10,  0],
       [ 0,  0,  0],
       [10, 10, 10]])
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-indexing
Numpy Array Indexing - GeeksforGeeks
December 17, 2025 - We can access elements by specifying row, column and depth indices like matrix[depth, row, column]. ... import numpy as np cube = np.array([[[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[10, 11, 12], [13, 14, 15], [16, 17, 18]]]) print(cube[1, 2, 0])
🌐
Pluralsight
pluralsight.com › blog › tech guides & tutorials
Working with Numpy Arrays: Indexing & Slicing | Pluralsight
Note that both the column and the row indices start with 0. So if I need to access the value ‘10,’ use the index ‘3’ for the row and index ‘1’ for the column. ... Let’s go one level higher. To access a three-dimensional array, include the index for the third dimension as well.
🌐
Python Like You Mean It
pythonlikeyoumeanit.com › Module3_IntroducingNumpy › AdvancedIndexing.html
Advanced Indexing — Python Like You Mean It
The index-arrays must have the same shape as one another, and this common shape determines the shape of the resulting array. This is a form of advanced indexing, and thus a copy of the parent array’s data is created. NumPy also permits the use of a boolean-valued array as an index, to perform advanced indexing on an array.
Find elsewhere
🌐
Medium
medium.com › @whyamit404 › basics-of-numpy-array-indexing-9052e6d6b5cf
Basics of NumPy Array Indexing. If you think you need to spend $2,000… | by whyamit404 | Medium
February 9, 2025 - Whether you want a specific range or skip every other slice, NumPy makes it easy. Let’s dive into the details! Slicing allows you to grab a portion of your array using the syntax: start:stop:step Here’s how it works: Start: The index where your slice begins (inclusive).
🌐
NumPy
numpy.org › devdocs › user › basics.indexing.html
Indexing on ndarrays — NumPy v2.6.dev0 Manual
The basic slice syntax is i:j:k where i is the starting index, j is the stopping index, and k is the step (\(k\neq0\)). This selects the m elements (in the corresponding dimension) with index values i, i + k, …, i + (m - 1) k where \(m = q + (r\neq0)\) and q and r are the quotient and remainder ...
🌐
W3Schools
w3schools.com › python › numpy › numpy_array_join.asp
NumPy Joining Array
Joining means putting contents of two or more arrays in a single array.
🌐
Reddit
reddit.com › r/python › python optimization
r/Python on Reddit: Python optimization
April 1, 2026 -

I’m working on a Python pipeline with two quite different parts.

The first part is typical tabular data processing: joins, aggregations, cumulative calculations, and similar transformations.

The second part is sequential/recursive: within each time-ordered group, some values for the current row depend on the results computed for the previous week’s row. So this is not a purely vectorizable row-independent problem.

I’m not looking for code-specific debugging, but rather for architectural advice on the best way to handle this kind of workload efficiently

I’d like to improve performance, but I don’t want to start by assuming there is only one correct solution.

My question is: for a problem like this, which approaches or frameworks would you recommend evaluating?

I must use Python

🌐
OpenAI Developers
developers.openai.com › api › docs › guides › embeddings
Vector embeddings | OpenAI API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20require "csv" require "fileutils" require "json" require "openai" client = OpenAI::Client.new reviews = ["A rich cup of coffee.", "A bright herbal tea."] response = client.embeddings.create( model: "text-embedding-3-small", input: reviews.map { |review| review.tr("\n", " ") } ) FileUtils.mkdir_p("output") CSV.open("output/embedded_1k_reviews.csv", "w") do |csv| csv << ["combined", "ada_embedding"] response.data.each do |embedding| csv << [reviews.fetch(embedding.index), JSON.generate(embedding.embedding)] end end · To load the data from a saved file, you can run the following: 1 2 3 4import pandas as pd df = pd.read_csv("output/embedded_1k_reviews.csv") df["ada_embedding"] = df.ada_embedding.apply(eval).apply(np.array)
🌐
Medium
medium.com › data-science › advanced-numpy-array-indexing-made-easy-fc49fdaef367
Advanced NumPy Array Indexing, Made Easy | by Andre Ye | TDS Archive | Medium
December 27, 2021 - Advanced NumPy Array Indexing, Made Easy Understand what [::2,[0,3,4],…,2:5] means One of NumPy’s biggest advantages is its extremely fast indexing, but it can get complex very quickly. For …
🌐
GeeksforGeeks
geeksforgeeks.org › python › indexing-multi-dimensional-arrays-in-python-using-numpy
Indexing Multi-dimensional arrays in Python using NumPy - GeeksforGeeks
November 4, 2025 - import numpy as np arr = np.arange(20, 30, 2) print(arr) print(arr[2]) # Access by index print(arr[1:4]) # Slice from index 1 to 3 ... We use reshape() with arange() to convert a 1D array into a 2D array.
🌐
W3Schools
w3schools.com › python › numpy › numpy_array_sort.asp
NumPy Sorting Arrays
The NumPy ndarray object has a function called sort(), that will sort a specified array.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-array-indexing
Python Array Indexing - GeeksforGeeks
July 1, 2026 - The first index selects the row, while the second index selects the column. A 3D array contains multiple 2D arrays.
🌐
Nature
nature.com › nature computational science › articles › article
Scaling and quantization of large-scale foundation model enables resource-efficient predictions in network biology | Nature Computational Science
March 27, 2026 - The 4-bit quantized Geneformer required only 15% of the fine-tuning time as the full-precision model with the same batch size (Fig. 2d). In addition, the quantized model required only 34% of the memory as the full-precision model with the same batch size (Fig.
🌐
Wikipedia
en.wikipedia.org › wiki › Softmax_function
Softmax function - Wikipedia
5 days ago - The softmax function, also known as softargmax or normalized exponential function, converts a tuple of K real numbers into a probability distribution over K possible outcomes. It is a generalization of the logistic function to multiple dimensions, and is used in multinomial logistic regression.
🌐
Nature
nature.com › scientific data › data descriptors › article
PDSXray: A Benchmark Dataset for Pseudocoloring-Driven Domain Adaptation in Security X-ray Inspection | Scientific Data
April 4, 2026 - The converted .txt files are named after the corresponding images and a labels.txt file is automatically created to serve as a category index, ensuring annotation consistency across subdomains.
🌐
GeeksforGeeks
geeksforgeeks.org › numpy › python-numpy
Python NumPy - GeeksforGeeks
Elements in a NumPy array can be accessed using indexing and slicing.
Published: June 12, 2026