Tag: numpy

53 votes
5 answers
2.6K views
What is the difference between ndarray and array in numpy?

What is the difference between ndarray and array in Numpy? And where can I find the implementations in the num

avatar
Majorie
0 1 0 9
asked 07 September, 2021
57 votes
8 answers
380 views
Most efficient way to reverse a numpy array

Believe it or not, after profiling my current code, the repetitive operation of numpy array reversion ate a gi

avatar
Robt
0 1 0 9
asked 07 September, 2021
61 votes
20 answers
2.9K views
Saving a Numpy array as an image

I have a matrix in the type of a Numpy array. How would I write it to disk it as an image? Any format works

avatar
Percy
0 1 0 9
asked 07 September, 2021
58 votes
6 answers
1.9K views
Concatenating two one-dimensional NumPy arrays

I have two simple one-dimensional arrays in NumPy. I should be able to concatenate them using numpy.concatenat

avatar
Hilario
0 1 0 9
asked 07 September, 2021
47 votes
17 answers
2.5K views
How do I check which version of NumPy I'm using?

How can I check which version of NumPy I'm using? (FYI this question has been edited because both the qu

avatar
Kristopher
0 1 0 9
asked 07 September, 2021
50 votes
7 answers
1.3K views
Comparing two NumPy arrays for equality, element-wise

What is the simplest way to compare two NumPy arrays for equality (where equality is defined as: A = B iff for

avatar
Hildegard
0 1 0 9
asked 07 September, 2021
62 votes
23 answers
2.8K views
What does axis in pandas mean?

Here is my code to generate a dataframe: import pandas as pd import numpy as np dff = pd.DataFrame(np.random

avatar
Kurtis
0 1 0 9
asked 07 September, 2021
64 votes
14 answers
1.7K views
NumPy array is not JSON serializable

After creating a NumPy array, and saving it as a Django context variable, I receive the following error when l

avatar
Dorinda
0 1 0 9
asked 07 September, 2021
62 votes
8 answers
1.2K views
How to convert a PIL Image into a numpy array?

Alright, I'm toying around with converting a PIL image object back and forth to a numpy array so I can do

avatar
Basil
0 1 0 9
asked 07 September, 2021
51 votes
4 answers
1.3K views
How to convert 2D float numpy array to 2D int numpy array?

How to convert real numpy array to int numpy array? Tried using map directly to array but it did not work.

avatar
Hildegard
0 1 0 9
asked 07 September, 2021
54 votes
3 answers
2.6K views
What is the difference between flatten and ravel functions in numpy?

import numpy as np y = np.array(((1,2,3),(4,5,6),(7,8,9))) OUTPUT: print(y.flatten()) [1 2 3 4 5 6

avatar
Arline
0 1 0 9
asked 07 September, 2021
60 votes
9 answers
1.3K views
Creating a Pandas DataFrame from a Numpy array: How do I specify the index column and column headers?

I have a Numpy array consisting of a list of lists, representing a two-dimensional array with row labels and c

avatar
Sena
0 1 0 9
asked 07 September, 2021
53 votes
13 answers
2.3K views
Converting between datetime, Timestamp and datetime64

How do I convert a numpy.datetime64 object to a datetime.datetime (or Timestamp)? In the following code, I cr

avatar
Adolfo
0 1 0 9
asked 07 September, 2021
65 votes
6 answers
1.5K views
What is the difference between Numpy's array() and asarray() functions?

What is the difference between Numpy's array() and asarray() functions? When should you use one rather th

avatar
Louetta
0 1 0 9
asked 07 September, 2021
52 votes
5 answers
612 views
Converting NumPy array into Python List structure?

How do I convert a NumPy array to a Python List (for example [[1,2,3],[4,5,6]] ), and do it reasonably fast?

avatar
Kurtis
0 1 0 9
asked 07 September, 2021
55 votes
17 answers
3.1K views
How to add an extra column to a NumPy array

Let’s say I have a NumPy array, a: a = np.array([ [1, 2, 3], [2, 3, 4] ]) And I would like

avatar
Majorie
0 1 0 9
asked 07 September, 2021
55 votes
15 answers
786 views
How do I create an empty array/matrix in NumPy?

I can't figure out how to use an array or matrix in the way that I would normally use a list. I want to c

avatar
Jefferey
0 1 0 9
asked 07 September, 2021
54 votes
7 answers
1.3K views
Difference between numpy.array shape (R, 1) and (R,)

In numpy, some of the operations return in shape (R, 1) but some return (R,). This will make matrix multiplica

avatar
Solomon
0 1 0 9
asked 07 September, 2021
53 votes
14 answers
1.8K views
How to pretty-print a numpy.array without scientific notation and with given precision?

I'm curious, whether there is any way to print formatted numpy.arrays, e.g., in a way similar to this: x

avatar
Joseph
0 1 0 9
asked 07 September, 2021
61 votes
11 answers
1.4K views
What does numpy.random.seed(0) do?

What does np.random.seed do in the below code from a Scikit-Learn tutorial? I'm not very familiar with Nu

avatar
Rudolf
0 1 0 9
asked 07 September, 2021