Python

Python is a dynamic, strongly typed, object-oriented, multipurpose programming language, designed to be quick (to learn, to use, and to understand), and to enforce a clean and uniform syntax. Two similar but incompatible versions of Python are in use (Python 2.7 or 3.x). For version-specific Python questions, please also use the [python-2.7] or [python-3.x] tags. When using a Python variant (Jython, Pypy, Iron-python, etc.) - please also tag the variant.

62 votes
5 answers
560 views
What are the differences between numpy arrays and matrices? Which one should I use?

What are the advantages and disadvantages of each? From what I've seen, either one can work as a replace

avatar
Sachiko
0 1 0 9
asked 07 September, 2021
53 votes
10 answers
2.5K views
Pandas conditional creation of a series/dataframe column

I have a dataframe along the lines of the below: Type Set 1 A Z 2 B Z

avatar
Janella
0 1 0 9
asked 07 September, 2021
64 votes
18 answers
809 views
Find nearest value in numpy array

Is there a numpy-thonic way, e.g. function, to find the nearest value in an array? Example: np.find_nearest

avatar
Dario
0 1 0 9
asked 07 September, 2021
69 votes
7 answers
437 views
What is the purpose of meshgrid in Python / NumPy?

Can someone explain to me what is the purpose of meshgrid function in Numpy? I know it creates some kind of gr

avatar
Yolando
0 1 0 9
asked 07 September, 2021
66 votes
3 answers
410 views
Simple Digit Recognition OCR in OpenCV-Python

I am trying to implement a "Digit Recognition OCR" in OpenCV-Python (cv2). It is just for learning purposes. I

avatar
Serina
0 1 0 9
asked 07 September, 2021
65 votes
8 answers
412 views
Numpy array dimensions

I'm currently trying to learn Numpy and Python. Given the following array: import numpy as np a = np.arr

avatar
Fabian
0 1 0 9
asked 07 September, 2021
48 votes
15 answers
432 views
Sorting arrays in NumPy by column

How can I sort an array in NumPy by the nth column? For example, a = array([[9, 2, 3], [4, 5, 6],

avatar
Nidia
0 1 0 9
asked 07 September, 2021
60 votes
10 answers
1.8K views
Pandas read_csv low_memory and dtype options

When calling df = pd.read_csv('somefile.csv') I get: /Users/josh/anaconda/envs/py27/lib/pytho

avatar
Fabian
0 1 0 9
asked 07 September, 2021
59 votes
7 answers
2.9K views
pandas create new column based on values from other columns / apply a function of multiple columns, row-wise

I want to apply my custom function (it uses an if-else ladder) to these six columns (ERI_Hispanic, ERI_AmerInd

avatar
Alphonso
0 1 0 9
asked 07 September, 2021
55 votes
17 answers
1.5K views
How to find all occurrences of an element in a list

index() will give the first occurrence of an item in a list. Is there a neat trick which returns all indices i

avatar
Shanita
0 1 0 9
asked 07 September, 2021
53 votes
13 answers
926 views
How do I read CSV data into a record array in NumPy?

I wonder if there is a direct way to import the contents of a CSV file into a record array, much in the way th

avatar
Arline
0 1 0 9
asked 07 September, 2021
60 votes
11 answers
1.4K views
Most efficient way to map function over numpy array

What is the most efficient way to map a function over a numpy array? The way I've been doing it in my cur

avatar
Lawanda
0 1 0 9
asked 07 September, 2021
47 votes
30 answers
793 views
How to count the occurrence of certain item in an ndarray?

In Python, I have an ndarray y that is printed as array([0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1]) I'm trying

avatar
Lynette
0 1 0 9
asked 07 September, 2021
65 votes
5 answers
2.6K views
What are the advantages of NumPy over regular Python lists?

What are the advantages of NumPy over regular Python lists? I have approximately 100 financial markets series

avatar
Emilia
0 1 0 9
asked 07 September, 2021
54 votes
17 answers
1.3K views
Is there a NumPy function to return the first index of something in an array?

I know there is a method for a Python list to return the first index of something: >>> l = [1, 2, 3]

avatar
Alba
0 1 0 9
asked 07 September, 2021
68 votes
11 answers
1.3K views
What does -1 mean in numpy reshape?

A numpy matrix can be reshaped into a vector using reshape function with parameter -1. But I don't know w

avatar
Sena
0 1 0 9
asked 07 September, 2021
47 votes
8 answers
1.7K views
How to access the ith column of a NumPy multidimensional array?

Suppose I have: test = numpy.array([[1, 2], [3, 4], [5, 6]]) test[i] gets me ith line of the array (eg [1,

avatar
Nidia
0 1 0 9
asked 07 September, 2021
62 votes
15 answers
744 views
Convert pandas dataframe to NumPy array

I am interested in knowing how to convert a pandas dataframe into a NumPy array. dataframe: import numpy as

avatar
Patsy
0 1 0 9
asked 07 September, 2021
51 votes
20 answers
2.3K views
How do I get indices of N maximum values in a NumPy array?

NumPy proposes a way to get the index of the maximum value of an array via np.argmax. I would like a similar

avatar
Lynette
0 1 0 9
asked 07 September, 2021
55 votes
22 answers
830 views
How can the Euclidean distance be calculated with NumPy?

I have two points in 3D: (xa, ya, za) (xb, yb, zb) And I want to calculate the distance: dist = sqrt((xa-xb)^

avatar
Vi
0 1 0 9
asked 07 September, 2021