Questions tagged [numpy]

NumPy is one of the fundamental packages used for scientific computing in the Python ecosystem. Specifically, NumPy is used for numerical computing and uses n-dimensional arrays.

What is NumPy?

NumPy is one of the fundamental packages used for scientific computing in the Python ecosystem. Specifically, NumPy is used for numerical computing and uses n-dimensional arrays. Topics include applications in quantum computing, statistical computing, image processing, bioinformatics, geosciences, chemistry, etc. It is also frequently used in machine learning and data visualization. It is open-sourced and distributed under the BDS License.


New to NumPy?

There are various resources including books, tutorials/workshops, etc. for those looking to learn how to use NumPy.

A popular introductory tutorial is:

SciPy 2019 Conference Tutorial:

An list of additional tutorials are listed on the NumPy website:


Tag Usage

When posting questions about numpy, please take the following into consideration:

  • Topics/use cases that involve the use of other packages as well should include all other relevant tags as well to make questions easier to find.

  • Explicit programming related questions are more suitable for Stack Overflow and should not be posted on Stack Exchange Data Science.

  • Questions should include sufficient details and clarity to be able to provide support for the problem at hand. This includes linking/showing underlying data being used, providing code, highlighting relevant outputs/desired outcomes, etc.


External Resources

numpy: Documentation page

numpy: GitHub page


Important links

Books

361 questions
2
votes
1 answer

ValueError: cannot reshape array of size 136415664 into shape (2734,132,126,1)

I have a data set I loaded with cv2, but when I try to format it I get the above error. I start by moving the data into X_train and X_test (the loaded data is in x_train and x_test). X_train = [] X_test = [] # Image matrices are different sizes so…
Finn Williams
  • 451
  • 1
  • 7
  • 17
1
vote
1 answer

np.unique() explanation?

What happends in this numpy function: https://numpy.org/doc/stable/reference/generated/numpy.unique.html a = np.array([1, 2, 5, 3, 2]) u, indices = np.unique(a, return_inverse=True) The results are: u array([1, 2, 3,…
martin
  • 329
  • 3
  • 12
1
vote
1 answer

np.shape[::-1] reversal of dims and np.moveaxis splitting array

I cannot find anything in the documentation but it was used in some starter code for a class I am taking at school. Upon testing per below, it seems to reverse the order of the dimensions of an numpy array. pic =…
mLstudent33
  • 594
  • 1
  • 5
  • 19
0
votes
1 answer

How to limit a function's cosine value as it approaches 0

How do I get a cosine to peak up to a certain value as it hits 0? With the above code, the y-value peaks to infinity as it approaches 0. import matplotlib.pyplot as plt import numpy as np amp = 1 time = np.linspace(-5, 5, 1000) signal = np.cos(1 *…
0
votes
1 answer

What is the use of the np.ndarray() function and how is it used?

I just started Data Science and I want to know what the np.ndarray() function's use is, and in which scenario(s) it is used.
0
votes
1 answer

Getting a transition matrix from a Adjacency matrix in python

I have a 3*3 Adjacency matrix and I'm trying to sum the elements of each column and divide each column element by that sum to get the transition matrix. Can you please help me code this part? Thanks in advance.
VishwaV
  • 379
  • 3
  • 6
  • 18
0
votes
1 answer

What is .numpy()?

I searched for numpy.numpy() and tried replacing .numpy() with .np() because numpy is already imported as np here: Tensorflow tutorial But using `.np() returns an error. In the section, "Creating training examples and targets" there is: # Create…
mLstudent33
  • 594
  • 1
  • 5
  • 19
0
votes
1 answer

Error with function

When i run this function - I get the following error below: I also checked my numpy version is 1.14 (which is higher than 1.7 when this issue was reported/resolved previously) - but still cant get to run this without error. def rank_to_dict(ranks,…
Patrick
  • 139
  • 4
0
votes
1 answer

Generate max likelyhood masks in numpy

We have several "in_arrays" like in_1=np.array([0.4,0.7,0.8,0.3]) in_2=np.array([0.9,0.8,0.6,0.4]) I need to create two outputs like out_1=np.array([0,0,1,0]) out_2=np.array([1,1,0,0]) So, the given element of the output array is 1 if the value in…
sixtytrees
  • 201
  • 1
  • 8
0
votes
1 answer

How to convert post-padded sequence to pre-padded sequence?

I have numpy array as follows: train_x = [[1,2,3,0,0], [2,5,0,0,0], [2,3,0,0,0], [0,0,0,0,0], [0,0,0,0,0,0]] Now, I would like to transform it to as shown below: new_train_x = [[0,0,0,0,0],[0,0,0,0,0,0],[0,0,1,2,3],[0,0,0,2,5],[0,0,0,2,3]] I tried…
Abc1729
  • 15
  • 4
-2
votes
1 answer

Numpy failing in subtraction even after same dimensions of arrays

When I subtract these two arrays, it returns a (354,354) shaped array because as per the documentation there is a mismatch in the shape of the arrays. Why does it happen and what else can I do for this except numpy.reshape ?