Tag: python

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
47 votes
11 answers
450 views
Dump a NumPy array into a csv file

Is there a way to dump a NumPy array into a CSV file? I have a 2D NumPy array and need to dump it in human-rea

avatar
Joseph
0 1 0 9
asked 07 September, 2021
57 votes
21 answers
1.9K views
How to print the full NumPy array, without truncation?

When I print a numpy array, I get a truncated representation, but I want the full array. Is there any way to

avatar
Cortez
0 1 0 9
asked 07 September, 2021
56 votes
18 answers
2.3K views
How to get the last element of a list?

In Python, how do you get the last element of a list?

avatar
Margo
0 1 0 9
asked 07 September, 2021
55 votes
11 answers
1.4K views
Why is "1000000000000000 in range(1000000000000001)" so fast in Python 3?

It is my understanding that the range() function, which is actually an object type in Python 3, generates its

avatar
Elicia
0 1 0 9
asked 07 September, 2021
57 votes
29 answers
1.5K views
How do I parse a string to a float or int?

In Python, how can I parse a numeric string like "545.2222" to its corresponding float value, 545.2222? Or par

avatar
Carmelina
0 1 0 9
asked 07 September, 2021
54 votes
24 answers
2.6K views
Converting string into datetime

I've got a huge list of date-times like this as strings: Jun 1 2005 1:33PM Aug 28 1999 12:00AM I&apos

avatar
Fabian
0 1 0 9
asked 07 September, 2021
52 votes
15 answers
3.1K views
How to access environment variable values

I set an environment variable that I want to access in my Python application. How do I get its value?

avatar
Wilfredo
0 1 0 9
asked 07 September, 2021
58 votes
30 answers
495 views
How to print colored text to the terminal?

How can I output colored text to the terminal in Python?

avatar
Hallie
0 1 0 9
asked 07 September, 2021
60 votes
22 answers
2.3K views
How do you change the size of figures drawn with Matplotlib?

How do you change the size of figure drawn with Matplotlib?

avatar
Keith
0 1 0 9
asked 07 September, 2021
52 votes
30 answers
1.2K views
How do you split a list into evenly sized chunks?

I have a list of arbitrary length, and I need to split it up into equal size chunks and operate on it. There a

avatar
Lawanda
0 1 0 9
asked 07 September, 2021