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
65
votes
16 answers

How do I install SciPy on 64 bit Windows?

How do I install SciPy on my system? For the NumPy part (that SciPy depends on) there is actually an installer for 64 bit Windows: numpy-1.3.0.win-amd64-py2.6.msi (is direct download URL, 2310144 bytes). Running the SciPy superpack installer results…
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
65
votes
5 answers

AttributeError: 'module' object (scipy) has no attribute 'misc'

I updated from ubuntu 12.04 to ubuntu 12.10 and the python module I have written suddenly no longer works with the error message that the module scipy does not have the attribute 'misc'. This worked previously. I am still using python 2.7 after the…
moadeep
  • 3,988
  • 10
  • 45
  • 72
64
votes
6 answers

SciPy Create 2D Polygon Mask

I need to create a numpy 2D array which represents a binary mask of a polygon, using standard Python packages. input: polygon vertices, image dimensions output: binary mask of polygon (numpy 2D array) (Larger context: I want to get the distance…
Isaac Sutherland
  • 3,082
  • 4
  • 28
  • 37
63
votes
6 answers

Is the order of a Python dictionary guaranteed over iterations?

I'm currently implementing a complex microbial food-web in Python using SciPy.integrate.ode. I need the ability to easily add species and reactions to the system, so I have to code up something quite general. My scheme looks something like…
Chinmay Kanchi
  • 62,729
  • 22
  • 87
  • 114
63
votes
4 answers

How to extend an array in-place in Numpy?

Currently, I have some code like this import numpy as np ret = np.array([]) for i in range(100000): tmp = get_input(i) ret = np.append(ret, np.zeros(len(tmp))) ret = np.append(ret, np.ones(fixed_length)) I think this code is not efficient as…
Hanfei Sun
  • 45,281
  • 39
  • 129
  • 237
62
votes
9 answers

Selecting Pandas Columns by dtype

I was wondering if there is an elegant and shorthand way in Pandas DataFrames to select columns by data type (dtype). i.e. Select only int64 columns from a DataFrame. To elaborate, something along the lines of df.select_columns(dtype=float64)
caner
  • 623
  • 1
  • 6
  • 7
62
votes
2 answers

Does `anaconda` create a separate PYTHONPATH variable for each new environment?

I am starting to work with the Python Anaconda distribution from Continuum.io to do scipy work. I have been able to get Anaconda up and running, but I cannot tell whether Anaconda creates a new PYTHONPATH environment variable for each new…
krishnab
  • 9,270
  • 12
  • 66
  • 123
61
votes
3 answers

Find matching rows in 2 dimensional numpy array

I would like to get the index of a 2 dimensional Numpy array that matches a row. For example, my array is this: vals = np.array([[0, 0], [1, 0], [2, 0], [0, 1], [1, 1], …
b10hazard
  • 7,399
  • 11
  • 40
  • 53
60
votes
4 answers

matplotlib - extracting data from contour lines

I would like to get data from a single contour of evenly spaced 2D data (an image-like data). Based on the example found in a similar question: How can I get the (x,y) values of the line that is ploted by a contour plot (matplotlib)? >>> import…
dtlussier
  • 3,018
  • 2
  • 26
  • 22
59
votes
3 answers

Obtain eigen values and vectors from sklearn PCA

How I can get the the eigen values and eigen vectors of the PCA application? from sklearn.decomposition import PCA clf=PCA(0.98,whiten=True) #converse 98% variance X_train=clf.fit_transform(X_train) X_test=clf.transform(X_test) I can't find…
Abhishek Bhatia
  • 9,404
  • 26
  • 87
  • 142
59
votes
5 answers

Generating Discrete random variables with specified weights using SciPy or NumPy

I am looking for a simple function that can generate an array of specified random values based on their corresponding (also specified) probabilities. I only need it to generate float values, but I don't see why it shouldn't be able to generate any…
TimY
  • 5,256
  • 5
  • 44
  • 57
58
votes
5 answers

scipy linkage format

I have written my own clustering routine and would like to produce a dendrogram. The easiest way to do this would be to use scipy dendrogram function. However, this requires the input to be in the same format that the scipy linkage function…
geo_pythoncl
  • 927
  • 1
  • 7
  • 13
58
votes
3 answers

Convert Pandas dataframe to Sparse Numpy Matrix directly

I am creating a matrix from a Pandas dataframe as follows: dense_matrix = np.array(df.as_matrix(columns = None), dtype=bool).astype(np.int) And then into a sparse matrix with: sparse_matrix = scipy.sparse.csr_matrix(dense_matrix) Is there any way…
user7289
  • 32,560
  • 28
  • 71
  • 88
57
votes
4 answers

transform scipy sparse csr to pandas?

I have used the sklearn.preprocessing.OneHotEncoder to transform some data the output is scipy.sparse.csr.csr_matrix how can I merge it back into my original dataframe along with the other columns? I tried to use pd.concat but I get TypeError:…
KillerSnail
  • 3,321
  • 11
  • 46
  • 64
57
votes
3 answers

Is there a numpy/scipy dot product, calculating only the diagonal entries of the result?

Imagine having 2 numpy arrays: > A, A.shape = (n,p) > B, B.shape = (p,p) Typically p is a smaller number (p <= 200), while n can be arbitrarily large. I am doing the following: result = np.diag(A.dot(B).dot(A.T)) As you can see, I am keeping only…
user2051916
  • 1,401
  • 1
  • 10
  • 10