Tag: python

67 votes
12 answers
1.3K views
Calling Python in Java?

I am wondering if it is possible to call python functions from java code using jython, or is it only for calli

avatar
Clarice
0 1 0 9
asked 07 September, 2021
57 votes
23 answers
2.8K views
52 votes
7 answers
1.1K views
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I just discovered a logical bug in my code which was causing all sorts of problems. I was inadvertently doing

avatar
Dwain
0 1 0 9
asked 07 September, 2021
52 votes
8 answers
1K views
dropping infinite values from dataframes in pandas?

what is the quickest/simplest way to drop nan and inf/-inf values from a pandas DataFrame without resetting mo

avatar
Scot
0 1 0 9
asked 07 September, 2021
56 votes
7 answers
1.9K views
NumPy array initialization (fill with identical values)

I need to create a NumPy array of length n, each element of which is v. Is there anything better than: a = e

avatar
Chaya
0 1 0 9
asked 07 September, 2021
62 votes
16 answers
1.9K views
Better way to shuffle two numpy arrays in unison

I have two numpy arrays of different shapes, but with the same length (leading dimension). I want to shuffle e

avatar
Wilfredo
0 1 0 9
asked 07 September, 2021
55 votes
16 answers
1.5K views
numpy: most efficient frequency counts for unique values in an array

In numpy / scipy, is there an efficient way to get frequency counts for unique values in an array? Something

avatar
Xavier
0 1 0 9
asked 07 September, 2021
53 votes
10 answers
638 views
How to take column-slices of dataframe in pandas

I load some machine learning data from a CSV file. The first 2 columns are observations and the remaining colu

avatar
Basil
0 1 0 9
asked 07 September, 2021
57 votes
10 answers
595 views
How do I convert a numpy array to (and display) an image?

I have created an array thusly: import numpy as np data = np.zeros( (512,512,3), dtype=np.uint8) data[256,256

avatar
Tana
0 1 0 9
asked 07 September, 2021
57 votes
13 answers
1.8K views
Converting numpy dtypes to native python types

If I have a numpy dtype, how do I automatically convert it to its closest python data type? For example, num

avatar
Lashawna
0 1 0 9
asked 07 September, 2021
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
377 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