Questions tagged [scipy]

SciPy is an open source library of algorithms and mathematical tools for the Python programming language.

SciPy is an open-source library for the programming language consisting of mathematical algorithms and functions for manipulating and visualizing data, often used in science and engineering. SciPy includes algorithms and tools for tasks such as optimization, clustering, discrete Fourier transforms, linear algebra, signal processing and multi-dimensional image processing.

SciPy is closely related to NumPy and depends on many functions, including a multidimensional array that is used as the basic data structure in SciPy.

SciPy is currently distributed under the BSD license.

Latest stable version:

1.6.0 (2020-12-31)

Documentation:

https://docs.scipy.org/doc/scipy/reference/

18169 questions
470
votes
12 answers

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 that R's read.table(), read.delim(), and read.csv() family imports data to R's data frame? Or is the best way to use csv.reader() and then…
hatmatrix
  • 36,897
  • 38
  • 126
  • 217
452
votes
12 answers

Read .mat files in Python

Is it possible to read binary MATLAB .mat files in Python? I've seen that SciPy has alleged support for reading .mat files, but I'm unsuccessful with it. I installed SciPy version 0.7.0, and I can't find the loadmat() method.
Gilad Naor
  • 18,017
  • 14
  • 44
  • 52
396
votes
14 answers

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], [7, 0, 5]]) I'd like to sort rows by the second column, such that I get back: array([[7, 0, 5], [9, 2, 3], [4, 5,…
user248237
278
votes
7 answers

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 mode.use_inf_as_null? I'd like to be able to use the subset and how arguments of dropna, except with inf values considered missing,…
user248237
265
votes
8 answers

Relationship between SciPy and NumPy

SciPy appears to provide most (but not all [1]) of NumPy's functions in its own namespace. In other words, if there's a function named numpy.foo, there's almost certainly a scipy.foo. Most of the time, the two appear to be exactly the same,…
NPE
  • 438,426
  • 93
  • 887
  • 970
245
votes
28 answers

Import Error: No module named numpy

I have a very similar question to this question, but still one step behind. I have only one version of Python 3 installed on my Windows 7 (sorry) 64-bit system. I installed numpy following this link - as suggested in the question. The installation…
Seb
  • 2,837
  • 2
  • 15
  • 16
237
votes
9 answers

Does Conda replace the need for virtualenv?

I recently discovered Conda after I was having trouble installing SciPy, specifically on a Heroku app that I am developing. With Conda you create environments, very similar to what virtualenv does. My questions are: If I use Conda will it replace…
Kritz
  • 5,560
  • 11
  • 39
  • 64
235
votes
9 answers

How to smooth a curve in the right way?

Lets assume we have a dataset which might be given approximately by import numpy as np x = np.linspace(0,2*np.pi,100) y = np.sin(x) + np.random.random(100) * 0.2 Therefore we have a variation of 20% of the dataset. My first idea was to use the…
varantir
  • 5,697
  • 5
  • 27
  • 50
232
votes
28 answers

Moving average or running mean

Is there a SciPy function or NumPy function or module for Python that calculates the running mean of a 1D array given a specific window?
Shejo284
  • 3,747
  • 4
  • 25
  • 35
208
votes
15 answers

Installing SciPy with pip

It is possible to install NumPy with pip using pip install numpy. Is there a similar possibility with SciPy? (Doing pip install scipy does not work.) Update The package SciPy is now available to be installed with pip!
Olivier Verdier
  • 41,410
  • 26
  • 94
  • 89
207
votes
17 answers

Calculating Pearson correlation and significance in Python

I am looking for a function that takes as input two lists, and returns the Pearson correlation, and the significance of the correlation.
ariel
  • 2,079
  • 2
  • 13
  • 3
198
votes
3 answers

What are the differences between Pandas and NumPy+SciPy in Python?

They both seem exceedingly similar and I'm curious as to which package would be more beneficial for financial data analysis.
user1462733
191
votes
11 answers

Is there a library function for Root mean square error (RMSE) in python?

I know I could implement a root mean squared error function like this: def rmse(predictions, targets): return np.sqrt(((predictions - targets) ** 2).mean()) What I'm looking for if this rmse function is implemented in a library somewhere,…
siamii
  • 20,540
  • 26
  • 86
  • 136
189
votes
7 answers

How to do exponential and logarithmic curve fitting in Python? I found only polynomial fitting

I have a set of data and I want to compare which line describes it best (polynomials of different orders, exponential or logarithmic). I use Python and Numpy and for polynomial fitting there is a function polyfit(). But I found no such functions for…
Tomas Novotny
  • 5,727
  • 7
  • 22
  • 23
183
votes
7 answers

How to add a new row to an empty numpy array

Using standard Python arrays, I can do the following: arr = [] arr.append([1,2,3]) arr.append([4,5,6]) # arr is now [[1,2,3],[4,5,6]] However, I cannot do the same thing in numpy. For example: arr = np.array([]) arr = np.append(arr,…
Tony Stark
  • 2,843
  • 7
  • 23
  • 29
1
2 3
99 100