Skip to main content

All Questions

2 votes
1 answer
140 views

Problem with mismatched length when using a mask

I'm writing a code and I have a function that calculates the values that are not fulfilling a condition with the values that are fulfilling the condition, but I'm having a lot of trouble with managing ...
alvarito mendez's user avatar
0 votes
3 answers
76 views

python and problems with passing array to a function

I need to solve some ordinary differential equation dy/dx = f(x) = x^2 ln(x) and to proceed I create the array xpt between the limits 0. <= xpt <= 2. Because I have to be careful at xpt = 0, I ...
jim's user avatar
  • 165
0 votes
1 answer
52 views

Is it possible that my python code for calculating numerical partial derivatives can be further simplified?

I want to compute the 1st-order partial derivatives of a 3D Cartesian mesh with shape (Nmesh, Nmesh, Nmesh), e.g. Nmesh=512 by the fourth-order accuracy scheme, i.e. f'(n) = 2*(f(n+1)-f(n-1))/(3*dh) - ...
Stephen Wong's user avatar
0 votes
0 answers
23 views

How to implement struct.unpack in Java with Integer type? [duplicate]

Following the similar question, I am trying to implement the unpack method in Java for Integer: Sample byte array input: chunkByte[1219:1240] = [64, 30, 31, 0, 64, 118, 31, 0, 64, -22, 29, 0, 64, 4, ...
newbie5050's user avatar
0 votes
0 answers
42 views

Mismatched Vector Sizes: operands could not be broadcast together with shapes (2,) (99,) - need help checking array syntax/operations

I am attempting to calculate the following five-point symmetric scheme for the diffusion equation (temperature diffusing through a rod with end points having temp = 100 degrees C). This is the formula ...
vincentledvina's user avatar
0 votes
1 answer
58 views

How I can pass data of methods to others using oop, for example with numerical methods in python

This error appears, ValueError: setting an array element with a sequence. I did it without oop and work it nice. I need the data of def loop(self): to pass it to the def f(self, x, y): and keeping the ...
Fabian Zamora's user avatar
0 votes
2 answers
110 views

What is the reason for IndexError: list index out of range?

So, my professor asked me to create a program that will use the Runge-Kutta Method (2nd order) to solve the problem. But I get an IndexError: list index out of range which goes back to my first ...
Казбек Ильясов's user avatar
2 votes
2 answers
143 views

Trying to understand syntax with index slicing in python matrix

I have been looking over and interpreting some sample code and am having some trouble understanding what is going on with a bit of slicing syntax. For some context I am working on a computational ...
Chase Gammon's user avatar
2 votes
0 answers
101 views

Why is my array returning a repeated single value

I have this code which is supposed to return a list of different spatial distances. However, when I print the array, it is only a single value filled in the array which is clearly wrong. The logic ...
M.Bore 's user avatar
2 votes
2 answers
3k views

How to calculate boundary points of numerical derivative in python?

I'm trying to write a function to take the derivative of any general function / array of numbers. Specifically, I am using a Central difference formula. The issue is, I cannot compute the boundary ...
PyRsquared's user avatar
  • 7,338
1 vote
1 answer
551 views

Numpy/Python numerical instability issue multiplying large arrays

I have created a function to rotate a vector by a quaternion: def QVrotate_toLocal(Quaternion,Vector): #NumSamples x Quaternion[w,x,y,z] #NumSamples x Vector[x,y,z] #For example shape (...
Ian Campbell Moore's user avatar
0 votes
2 answers
138 views

Move from an array of 'labels' to array of equations corresponding to those labels in Python 2.7

How can I efficiently move from an array of essentially labels to equations corresponding to those labels in python 2.7? This image illustrates what I mean: The equations pull values from array x, so ...
Tom Stockman's user avatar
2 votes
2 answers
5k views

numpy - Sample repeatedly from matrix using np.random.choice

I have a 2D array, where each row is a direction: directions = np.array([[ 1, 0], [-1, 0], [ 0, 1], [ 0,-1]]) I want to sample ...
user1496984's user avatar
  • 11.6k
15 votes
4 answers
12k views

argsort for a multidimensional ndarray

I'm trying to get the indices to sort a multidimensional array by the last axis, e.g. >>> a = np.array([[3,1,2],[8,9,2]]) And I'd like indices i such that, >>> a[i] array([[1, 2, 3]...
DilithiumMatrix's user avatar