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.

103,352 questions
0votes
0answers
12views

In NumPy: How to detect whether an argument is a "ragged nested sequences"

If obj is a list of "ragged nested sequences", like obj = [1, 2, [3, 4]], then np.array(obj) produces a warning: "Creating an ndarray from ragged nested sequences ... is deprecated...&...
1vote
2answers
22views

how to change shape of 3d array

I have a 3d array in shape (288,512,512) that 288 is the number of images and 512*512 is the width and height of the image. Also, there is a mask array of this image in shape (512,512,288). How can I ...
1vote
1answer
21views

How to set second and following occurrences of 0 to NaN in python

I am trying to figure out how to set all second occurrences of 0 in my dataframe to NaN in python. However, this is a tranposed dataframe so 0 would occur across the columns. To explain, I have the ...
0votes
0answers
15views

BUILD FAIL ON HEROKU

Trying to deploy a python application on Heroku, however it fails in building with the following log: Building wheels for collected packages: numpy, pandas, scikit_learn, tornado, blinker, ...
0votes
0answers
12views

Saving a CV2 numpy array to SVG file format

I am working on a document image analysis project. Part of the work is to capture an image (usually contains text in the form of tables) from the document and embed it in the html file. For now, I ...
0votes
2answers
22views

How to grab corresponding values from two-dimensional numpy array

I have a two-dimension array [[ 1, 4, 4, 6, 6, 6, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 11, 11, 11, 11, 11], [ 0, 0, 1, 0, 1, 4, 0, 1, 4, 6, 0, 1, 4, 6, 8, 5, 0, 1, 4, 6, 8]...
1vote
0answers
20views

How to draw a straight line between two points on a heatmap

I am creating a 2D matplotlib plot (i and j coordinates) which contains 10 subplots. Each subplot contains 150 by 150 grid cell data. How can I insert a thick straight line arrow (color = red) that ...
0votes
0answers
25views

trying to get ratio of numbers in a rolling window. TypeError: unsupported operand type(s) for /: 'Rolling' and 'int'

im trying to get the ratio of numbers of a certain column that are above 0 in a rolling window as a new column. i tried the following: df['ratio'] = pd.DataFrame.rolling(df[df['column']>0].count(),...
0votes
0answers
20views

Numpy - Map data to a matrix based on index location

First, I am only assuming Numpy is the best way to do this, but I'm open to other better suited packages (pandas?). I am looking to map the following data into a matrix format (to eventually display ...
0votes
0answers
11views

How to mask only the most recent date?

Let's say I have 2 days worth of date times: import pandas as pd import numpy as np index = pd.date_range("2020-01-01 00:00:00", "2020-01-03 00:00:00", freq="15T") ...
  • 2,778
0votes
0answers
16views

Python find the long axis of a 3D point cloud or 3D hull

I am trying to find the 'long axis' of a 3D object (described as a 3D boolean or label array), which passes through (or near) the centroid of that object. I would like to think I could simply iterate ...
  • 335
0votes
1answer
27views

pandas dtypes column coercion

What would cause pandas to set a column type to 'object' when the values I have checked are strings? I have explicitly set that column to "string" in the dtypes dictionary settings in the ...
1vote
1answer
21views

Difference of Numpy Dimension Expand code

I got confuse between two Numpy dimension expand code. First code is X[:, np.newaxis]. Second code is X[:, np.newaxis, :]. I ran this code on Jupyter, But it returns same shape and result. What is the ...
0votes
3answers
22views

How to combine or join unique values from different columns in DataFrame?

This is my Dataset and I want to combine Symptom_1, Symptom_2, Symptom_3. The code that I used to combine them is df['Symptom'] = df.apply(lambda row: row.Symptom_1 + row.Symptom_2 + row.Symptom_3, ...
5votes
1answer
39views

Solve very large system of linear equations with Numpy

I'm trying to solve a system of equations that is a 1 Million x 1 Million square matrix and one 1 Million solution vector. To do this, I'm using np.linalg.solve(matrix, answers) but it's taking a very ...

153050per page