All Questions
2,390 questions
1
vote
1
answer
56
views
Discrepancy in Calculated Values from Iterative and Vectorized Sine Functions
I am working with a NetCDF file that contains latitude values, and I am attempting to compute the reciprocal of the sine values of latitude. The code I wrote is as follows:
import xarray as xr
import ...
0
votes
1
answer
88
views
Changing objects in a Python list according to boolean/binary vector
Let
L=[-1, 3, 4, -2, 6]
be a list and
indices=np.array([1, 0, 0, 1,1], dtype=bool)
a boolean vector. I would like to set the entries of L according to indices, e.g.
L[indices]= an object OBJ, so ...
-2
votes
2
answers
110
views
'list' object has no attribute 'replace'
I'm working on some code to encrypt a word into numbers from the polybius square, however I need the output to be the two numbers right next to each other e.g. 41 instead of a coordinate format (4, 1)....
0
votes
5
answers
144
views
Python list with NumPy arrays as elements
I have a list with NumPy arrays as elements that looks like this:
[array([ 0.2, -2.3, 5.3]),
array([-1.6, -1.7, 0.3]),
array([ 2.4, -0.2, -3.0]),
array([-4.1, -2.3, -2.7])]
and I want to convert ...
-2
votes
1
answer
92
views
Why are lists performing faster than numpy arrays in my n-body integrator?
I made a simple n-body integrator using Euler's method in python. I didn't know about numpy arrays, so I treated each vector as a list of x, y, and z variables. I even made my own magnitude() function ...
0
votes
0
answers
39
views
How can we access the index of an elements in numpy array? [duplicate]
import numpy as np
np_arr = np.array([[1, 2, 3], [4, 5, 6]])
condition = (np_arr > 2) & (np_arr < 5)
print(condition)
When we print(condition) - we get a boolean array which tells ...
0
votes
1
answer
55
views
How to Add New Column in Dictionary?
Based on the data below, I want to calculate the BMI Index for each row and the average for the total row. The BMI Index formula is 'berat' / 'tinggi'.
enter image description here
data = [{'nama': '...
0
votes
0
answers
65
views
Why is my function working only when I call it directly in the plot?
I wrote a function which rounds the value of the signal after the first maximum is obtained. However, when I call this function and store the result and plot it, I do not see the expected result.
This ...
1
vote
0
answers
72
views
Faster way to access the value of a huge dictionary from a huge list of arrays in python
I am curious whether I can access the value of a huge dictionary faster from a huge list of arrays.
Here is a simple example:
import numpy as np
my_list = [np.array([ 1, 2, 3, 4, 5, 6, 8, 9, 10]...
1
vote
3
answers
83
views
Most efficient way to keep track of the samples I already selected from an array
I have a moderately large np array (which could however get larger in the future):
import numpy as np
x = np.arange(100_000).reshape((10_000,10))
I need to iteratively choose a random sample (row), ...
0
votes
1
answer
39
views
Joining vectors with common elements from a list
I have a list of vectors and I want to join all the vectors inside the list which have some common components:
For example, I have:
list = [[1, 14], [3, 15], [4, 15], [5, 14], [8, 14], [9, 15], [10, ...
1
vote
0
answers
125
views
Working with 4D data in Python with entries having variable sizes (are not homogeneous)
I am a civil engineer and I need to collect results from a finite element model and work with data having four dimensions.
Load combinations in the building model (can range from 3 to 60 or so)
The ...
1
vote
1
answer
64
views
Taking the square root of multidimensional uncertainties uarray
How do I take the square root of a 2D uarray?
For example,
import numpy as np
from uncertainties import unumpy,umath
array=np.array([[2,3],[6,7],[5,3]])
uncertainties=np.array([[2,2],[4,4],[5,5]])
...
1
vote
1
answer
59
views
Is there a way to make a long for loop to run faster?
Im making a simple montecarlo simulator that takes in a 3*4 matrix of probabilities, and the number of iterations you want to simulate for. And the output is a table with all the results.
Each row of ...
0
votes
1
answer
53
views
Fail to change an element in an numpy.array in Python
import numpy as np
def function(1st_variable,2nd_variable):
ratio = 1st_variable/ 2nd_variable
y = np.power(ratio, 1.1)*0.79
if y >= value*0.89:
y = value*0.89
return y
...
2
votes
3
answers
86
views
how to merge two lists and get names of lists with the highest value for each index?
I am trying to compare two lists of odds from two bookmakers. They look like this:
List1 = ['2.66', '3.79', '1.88', '1.61', '2.51', '1.29', '2.29', '2.56', '3.16', '2.05', '2.95', '2.64', '2.26', '3....
0
votes
0
answers
50
views
Why does the following code detect this matrix as a non-singular matrix?
Here is a fragment of my code:
import numpy as np
from copy import copy
from random import randint
# With this matrix it doesn't give an error
matriz_aux = [
[None, 6, None, 9],
[ 9, None, ...
0
votes
1
answer
33
views
IndexError when I try to fill a list of lists from a multidimensional numpy array with expression statement in Python
Starting from a csv file, I have a multidimensional numpy array (dimensions: 617 x 9) and I need only one column of that n x m array. In that column are stored sequential data like the following:
[0,0,...
-1
votes
2
answers
111
views
Python coding question regarding "stacking arrays to an array" [closed]
I have a simple Python coding question regarding "stacking array inside array". Here, I have several arrays as follows:
a1 = np.array([[1,1,1],[1,1,1],[1,1,1]])
a2 = np.array([[2,2,2],[2,2,...
0
votes
0
answers
50
views
Matching parts from cut sequence to origin sequence, when origin sequence is very long
I have two numeric and huge np.arrays (let's call them S1 and S2, such that len(S1)>>len(S2)>>N where N is a very large number). Let us call S1 the origin sequence, and S2 the cut sequence....
1
vote
3
answers
99
views
Update the first element in a list containing range on integers
In a range of list that contains an interval (1-59/4) i want the first element alone to change for ever 3 rows.
n = 14
lis_num = []
for x in range(n):
lis_num.append('need the logic')
output of ...
2
votes
2
answers
72
views
Comparing a numeric Python's list against a Pandas dataframe
I have a Pandas's dataframe with 9 columns (called just dataframe), 5 of them called: [['DEG1','DEG2','DEG3','DEG4','DEG5']], it has almost 2000 rows. I have a list from which I build another ...
0
votes
1
answer
115
views
How to transpose a jagged 2D array in Python?
I'm trying to transpose a jagged 2D array called "seats."
seats = np.array([
[1, 2, 3, 4, 5],
[1, 2, 3, 4],
[1, 2, 3],
...
1
vote
1
answer
69
views
Python grouping numbers based on thresholds
I have 4 points indexed by 0,1,2 and 3 which all have relationships with each other which can be captured by a network or a 2d array like below. I want to group the numbers together based on a ...
-4
votes
1
answer
87
views
Write a function that takes list and returns list for every element where position of single element is exchanged with product of all other elements [closed]
My code doesn't empty the return list to only return a list with a single element being the product of all others. Why is that so? I would prefer a solution without numpy
def multiList(arr):
print(...
0
votes
2
answers
88
views
How can I multidimensionalise this code that finds indices from a list of values?
I have some code that finds the indices of elements in the "input" list that match any element in the "values" list. The indices are then outputted, arranged in the same order as ...
0
votes
0
answers
104
views
ufunc 'add' did not contain loop with matching data types
I have a dataframe where some columns has values and some are NaN type (basically float)
This is the dataframe-
I am looping over the decribe and referring columns and if that row has some file name, ...
0
votes
3
answers
164
views
How to convert a set of Python lists to numpy arrays?
I need to set the type of a set of arrays to be of the type np.ndarray each one. Since I need to do it multiple times, I'm trying a for loop, it seems to be correctly converting from list to np....
1
vote
1
answer
392
views
the generalized Marcum Q-function in python
I am trying to plot a CDF of a random variable that contains the generalized Marcum Q-function
How can I write the Q-function in python or which library it exist
I was searching in sci.py but I didn'...
0
votes
0
answers
49
views
Appending a row of an ND numpy object array [duplicate]
I'm trying to create an ND numpy object array to store data of different row lengths, but whenever I try to append an array by directly indexing that row, every row gets appended.
myArr = np.empty(10, ...
1
vote
1
answer
56
views
Why can I plot data arrays containing None values when using numpy array, but not when using list?
I have some data, X and Y, which I'd like to plot simply as X vs Y.
However, for some elements of Y, there is no data. I record this as None rather than 0, since matplotlib helpfully does not plot it (...
0
votes
1
answer
67
views
df style apply to specific cells
I have a dict which i create df
data = {'BTC': {'PNL': 834.8485, 'FUNDING': 575.20837762, 'DELTA VOL': 18845436.3535, 'HEDGE VOL': 16444662.545, 'OI': 4598885.7407, 'DEFICIT': 149.35084}, 'BTC 4HR': {'...
0
votes
0
answers
46
views
Why doesn't this function finish its calculation?
I'm writing a function that receives a matrix with the work shifts for each employee in a day and returns a matrix that contains how many people work each hour of the day. Each work shift looks like ...
0
votes
1
answer
62
views
Error invalid index to scalar variable how to solve when using shape function
I am trying to use the following function to make mutation step in agametic algorithm. Unfortunately, I have got an error as follows:
IndexError Traceback (most recent ...
0
votes
1
answer
165
views
Find lists of almost equal values in list
I have a 1D numpy array, and I want to find the sublists/subarrays that contain almost equal values. That means they don't differ from each other more than a tolerance. I mean there is one central ...
1
vote
1
answer
2k
views
np.array() gives error: inhomogeneous shape after 2 dimensions. The detected shape was (31, 3) + inhomogeneous part
I've run into an error that I've had some trouble fixing.
finBlackSourceMoves = np.array(finBlackSourceMoves)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: setting an array ...
0
votes
2
answers
97
views
Unable to add data to a numpy file
while (True):
if not paused:
screen = grab_screen(region=(0, 40, 800, 640))
screen = cv2.cvtColor(screen,
cv2.COLOR_BGR2GRAY) # Removing color can ...
0
votes
2
answers
52
views
How to remove rows from a dataframe based on partial match in an array
I have a dataframe with customer info including first and last name (seperate columns). I have an array of names and I want to remove rows if there is a partial match in the names.
For example, last ...
1
vote
1
answer
44
views
Python Lists - Return list of every nth element before known substring in a list
I have an array like so:
['6.00', '1.85', 'X', '2.25', '1.26', 'X', '6.50', '1.80', 'X', '6.50', '1.95', 'X', '34.00', '5.50']
Does anyone know how I could return an array of every 3rd element before ...
1
vote
1
answer
68
views
How to create a dataframe without getting empty values?
I have been using one algorithm, and also getting the desired output but when i am trying to convert both the outputs to a specific dataframe, i always receive empty dataframes, can anyone please tell ...
1
vote
1
answer
37
views
List of lists of mixed types to numpy array
I have data imported from csv and they are stored in list of lists as:
data=[['1', ' 1.013831', ' 1.713332', ' 1.327002', ' 3.674446', ' 19.995361', ' 09:44:24', ' 2.659884'], ['2', ' 1.013862', ' 1....
0
votes
1
answer
34
views
How can I extract key words from a list and create individual column for each one of them?
For example, I have a list like ['Hot Pot', 'Korean BBQ', 'BBQ', 'Korean'] or ['Desserts', 'Modern Australian'] under cuisine column
How can I extract each element from the list and creat separate ...
0
votes
1
answer
62
views
I would like to transform an Excel calculation into a Python program with the same results
A represents tasks that need to be processed on each machine. A total of 5 tasks are given T0 to T4.
B are the Setup values required to prepare a machine for processing a task that has been added ...
1
vote
2
answers
41
views
How can I control matrix zero to be 1 by predetermined column in Python?
Suppose I have some list of column like this:
res = [[2],[3, 4],[0],[5]]
Then, I need to change this zr zero matrix 4X4 to be 1 following column in res list above; For example: the first row plots ...
0
votes
3
answers
73
views
How can I and improve array matrix [0,1] by row and column constraints in Python?
Suppose I have an matrix array table.
uvv = np.array([[0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0,...
1
vote
5
answers
66
views
reverse order within sublist in numpy
I have two numpy arrays:
Values = numpy.array([5, 6, 7, 8, 1, 2, 3, 14, 15, 16])
Lengths = numpy.array([4, 3, 3])
What would be an efficient way to in numpy to reverse the order within the sublist ...
0
votes
2
answers
49
views
How to drop (delete) consecutive values in a Dataframe
I have a dataframe with a column that has 0 Values. I wish to find those 0 values and check if till the end they are 0, drop only those at the end and not in the middle.
this is how the Data in ...
0
votes
1
answer
1k
views
What is faster to create a pandas DataFrame row by row
I am downloading data from an API and using them to create a pandas DataFrame.
I am downloading the data row by row, and will often download over a million rows.
Currently, I created a list object, ...
0
votes
0
answers
34
views
Why appending a list is faster than changing the value of a numpy array? [duplicate]
To my surprise this code:
N = 10**8
l = []
L = np.zeros(N)
t1 = time()
for i in range(N):
l.append(1)
t2 = time()
print("Adding into list took:", t2 - t1, "s")
t1 = time()
...
0
votes
2
answers
44
views
How can I change zero matrix to one, according to the predetermined row and column in python?
Now, I have 12x18 of zero matrix :
zero = array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...