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.7.3 (2021-11-25)

Documentation:

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

21123 questions
560
votes
14 answers

How do I read CSV data into a record array in NumPy?

Is there a direct way to import the contents of a CSV file into a record array, just like how R's read.table(), read.delim(), and read.csv() import data into R dataframes? Or should I use csv.reader() and then apply numpy.core.records.fromrecords()?
hatmatrix
  • 42,883
  • 45
  • 137
  • 231
558
votes
16 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
  • 20,752
  • 14
  • 46
  • 53
505
votes
16 answers

Sorting arrays in NumPy by column

How do I sort a NumPy array by its nth column? For example, given: a = array([[9, 2, 3], [4, 5, 6], [7, 0, 5]]) I want to sort the rows of a by the second column to obtain: array([[7, 0, 5], [9, 2, 3], [4, 5,…
user248237
319
votes
27 answers

Error "Import Error: No module named numpy" on Windows

I have a very similar question to this question, but I am 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…
Seb
  • 3,655
  • 3
  • 17
  • 17
308
votes
10 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
  • 7,099
  • 12
  • 43
  • 73
293
votes
12 answers

How to smooth a curve for a dataset

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
  • 6,624
  • 6
  • 36
  • 57
293
votes
30 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
  • 4,541
  • 6
  • 32
  • 44
279
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
  • 486,780
  • 108
  • 951
  • 1,012
260
votes
14 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
  • 23,374
  • 28
  • 93
  • 143
232
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
  • 3,353
  • 7
  • 26
  • 30
230
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
  • 7,547
  • 9
  • 26
  • 23
223
votes
18 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,239
  • 2
  • 14
  • 3
218
votes
8 answers

How to normalize a NumPy array to within a certain range?

After doing some processing on an audio or image array, it needs to be normalized within a range before it can be written back to a file. This can be done like so: # Normalize audio channels to between -1.0 and +1.0 audio[:,0] =…
endolith
  • 25,479
  • 34
  • 128
  • 192
211
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
  • 46,998
  • 29
  • 98
  • 90
206
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
1
2 3
99 100