Answer by Ivorius for Faster numpy cartesian to spherical coordinate conversion?
I base my code on mrtw's answer - I added axis support, the reverse function and base it off a 3-tuple shape:def from_xyz(xyz, axis=-1): x, y, z = np.moveaxis(xyz, axis, 0) lea = np.empty_like(xyz)...
View ArticleAnswer by N.A. Borggren for Faster numpy cartesian to spherical coordinate...
Octave has some built-in functionality for coordinate transformations that can be accessed with the package oct2py to convert numpy arrays in Cartesian coordinates to spherical or polar coordinates...
View ArticleAnswer by Vincent for Faster numpy cartesian to spherical coordinate conversion?
! There is an error still in all the code above.. and this is a top Google result..TLDR:I have tested this with VPython, using atan2 for theta (elev) is wrong, useacos! It is correct for phi (azim).I...
View ArticleAnswer by rth for Faster numpy cartesian to spherical coordinate conversion?
To complete the previous answers, here is a Numexpr implementation (with a possible fallback to Numpy),import numpy as npfrom numpy import arctan2, sqrtimport numexpr as nedef cart2sph(x,y,z,...
View ArticleAnswer by mtrw for Faster numpy cartesian to spherical coordinate conversion?
This is similar to Justin Peel's answer, but using just numpy and taking advantage of its built-in vectorization:import numpy as npdef appendSpherical_np(xyz): ptsnew = np.hstack((xyz,...
View ArticleAnswer by Justin Peel for Faster numpy cartesian to spherical coordinate...
Here's a quick Cython code that I wrote up for this:cdef extern from "math.h": long double sqrt(long double xx) long double atan2(long double a, double b)import numpy as npcimport numpy as npcimport...
View ArticleFaster numpy cartesian to spherical coordinate conversion?
I have an array of 3 million data points from a 3-axiz accellerometer (XYZ), and I want to add 3 columns to the array containing the equivalent spherical coordinates (r, theta, phi). The following code...
View ArticleAnswer by Peyman for Faster numpy cartesian to spherical coordinate conversion?
You can use hyperspherical package. It works for any dimension.import numpy as npfrom hyperspherical import cartesian2spherical, spherical2cartesianxyz = np.random.rand(3000000,3)%timeit r_theta_phi =...
View Article