Questions tagged [numpy]

NumPy is an extension of the Python language that adds support to large multidimensional arrays and matrixes, along with a large library of high-level mathematical functions for operations with these arrays.

About NumPy

From the NumPy homepage:

NumPy is the fundamental package for scientific computing with . It contains among other things:

  • a powerful N-dimensional array object
  • built-in universal functions (ufuncs)
  • sophisticated (broadcasting) operation
  • tools for integrating C/C++ and Fortran code
  • useful linear algebra, Fourier transform, and random number capabilities

Besides its obvious scientific uses, NumPy can also be used as an efficient multi-dimensional container of generic data. Arbitrary data-types can be defined. This allows NumPy to seamlessly and speedily integrate with a wide variety of databases.

NumPy provides reliable and efficient methods of data storage, manipulation, and analysis as it also integrates easily with other methods of data manipulation, notably Pandas and scikit-learn.

NumPy is released under the BSD license, enabling reuse with few restrictions.

Resources

Official Resources

Books

90394 questions
23
votes
1 answer

How do I read numpy source?

I built it myself on Python 3.3, but I can't for the life of me find the class definition of numpy.array(). I've looked all through the code and even found the core C files, but where is the dang array class?? Can anyone tell me what directory to…
mrKelley
  • 2,925
  • 1
  • 17
  • 28
23
votes
15 answers

Simplest way to solve mathematical equations in Python

I want to solve a set of equations, linear, or sometimes quadratic. I don't have a specific problem, but often, I have been in this situation often. It is simple to use wolframalpha.com, the web equivalent of Mathematica, to solve them. But that…
Lakshman Prasad
  • 76,135
  • 46
  • 128
  • 164
23
votes
2 answers

Concatenating column vectors using numpy arrays

I'd like to concatenate 'column' vectors using numpy arrays but because numpy sees all arrays as row vectors by default, np.hstack and np.concatenate along any axis don't help (and neither did np.transpose as expected). a = np.array((0, 1)) b =…
green diod
  • 1,211
  • 2
  • 10
  • 23
23
votes
4 answers

PIL image to array (numpy array to array) - Python

I have a .jpg image that I would like to convert to Python array, because I implemented treatment routines handling plain Python arrays. It seems that PIL images support conversion to numpy array, and according to the documentation I have written…
kiriloff
  • 22,522
  • 32
  • 127
  • 207
23
votes
7 answers

python: getting around division by zero

I have a big data set of floating point numbers. I iterate through them and evaluate np.log(x) for each of them. I get RuntimeWarning: divide by zero encountered in log I would like to get around this and return 0 if this error occurs. I am…
Julia
  • 1,279
  • 4
  • 14
  • 36
23
votes
7 answers

Is there a numpy.delete() equivalent for sparse matrices?

Let's say I have a 2-dimensional matrix as a numpy array. If I want to delete rows with specific indices in this matrix, I use numpy.delete(). Here is an example of what I mean: In [1]: my_matrix = numpy.array([ ...: [10, 20, 30, 40, 50], …
pemistahl
  • 8,249
  • 6
  • 40
  • 69
23
votes
3 answers

How to show the whole image when using OpenCV warpPerspective

I have 2 test images here. My is question is, how to map the square in first image to the quadrilateral in the second image without cropping the image. Image 1: Image 2: Here is my current code using openCV warpPerspective function. import…
Rafiq Rahim
  • 375
  • 1
  • 4
  • 11
23
votes
6 answers

Can't import Numpy in Python

I'm trying to write some code that uses Numpy. However, I can't import it: Python 2.6.2 (r262, May 15 2009, 10:22:27) [GCC 3.4.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy Traceback (most…
Nathan Fellman
  • 108,984
  • 95
  • 246
  • 308
23
votes
1 answer

TypeError generated when using inplace operations on numpy arrays?

If I run the following code: import numpy as np b = np.zeros(1) c = np.zeros(1) c = c/2**63 print b, c b += c I get this error message: TypeError: ufunc 'add' output (typecode 'O') could not be coerced to provided output parameter (typecode 'd')…
Aae
  • 355
  • 1
  • 3
  • 12
23
votes
8 answers

Numpy Indexing: Return the rest

A simply example of numpy indexing: In: a = numpy.arange(10) In: sel_id = numpy.arange(5) In: a[sel_id] Out: array([0,1,2,3,4]) How do I return the rest of the array that are not indexed by sel_id? What I can think of is: In: numpy.array([x for x…
CJLam
  • 691
  • 2
  • 7
  • 14
23
votes
2 answers

Creating a 3D plot from a 3D numpy array

Ok, so I feel like there should be an easy way to create a 3-dimensional scatter plot using matplotlib. I have a 3D numpy array (dset) with 0's where I don't want a point and 1's where I do, basically to plot it now I have to step through three for:…
pter
  • 541
  • 2
  • 6
  • 15
23
votes
1 answer

Adding a vector to matrix rows in numpy

Is there a fast way in numpy to add a vector to every row or column of a matrix. Lately, I have been tiling the vector to the size of the matrix, which can use a lot of memory. For example mat=np.arange(15) mat.shape=(5,3) …
user1149913
  • 4,354
  • 1
  • 19
  • 25
23
votes
6 answers

Matplotlib requirements with pip install in virtualenv

I have a requirements.txt file like this: numpy matplotlib When I try pip install -r requirements.txt inside a new virtualvenv, I get this: REQUIRED DEPENDENCIES numpy: no * You must install numpy 1.1 or later to…
msampaio
  • 3,014
  • 4
  • 27
  • 50
23
votes
4 answers

What is the best way of getting random numbers in NumPy?

I want to generate random numbers in the range -1, 1 and want each one to have equal probability of being generated. I.e. I don't want the extremes to be less likely to come up. What is the best way of doing this? So far, I have used: 2 *…
wot
  • 339
  • 1
  • 3
  • 13
23
votes
2 answers

Julia's Python performance example in pypy

Julia is a new statistical programming language that claims significantly better performance than competing languages. I'm trying to verify this. Julia has a performance test written in…
SFun28
  • 32,209
  • 43
  • 123
  • 233
1 2 3
99
100