Quantcast
Channel: Faster numpy cartesian to spherical coordinate conversion? - Stack Overflow
Browsing latest articles
Browse All 8 View Live

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 Article


Answer 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 Article


Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer 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 Article

Faster 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 Article

Answer 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

Browsing latest articles
Browse All 8 View Live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>