Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8833635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:49:39+00:00 2026-06-14T08:49:39+00:00

considering I have a 3D histogram or for simplicity a 3D numpy array of

  • 0

considering I have a 3D histogram or for simplicity a 3D numpy array of shape (X,Y,Z)

import numpy as np
array = np.random.random((100,100,100))

What is the best way, using numpy or scipy to obtain array’s values’ indexes of which satisfy a sphere conditions?

(index_x**2 + index_y**2 + index_z**2) <= radius**2

Obvioulsy, in the later condition, the array center is (0, 0, 0). In general the condition will be

((index_x-center_x)**2 + (index_y-center_y)**2 +(index_z-center_z)**2) <= radius**2

The problem is easy to solve using simply a python loop, but I need that to be optimized.

many thanks for your help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:49:41+00:00Added an answer on June 14, 2026 at 8:49 am

    Just for making @EOL nice approach more general, one can define a center within the shape of the array

    array = np.random.random((100,100,100))
    center = (30,10,25)
    radius = 5.0
    x, y, z = np.ogrid[-center[0]:array.shape[0]-center[0],-center[1] :array.shape[1]-center[1], -center[2]:array.shape[2]-center[2]]
    indexes = numpy.transpose((x**2+y**2+z**2 <= radius**2).nonzero())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been considering the problems arising with user authentication, using sessions/cookies and the
I have a question considering a program that stimulates a stack (not using any
I have a PHP file that contains a large array (about 90KB). I'm considering
I'm considering using JRuby on App Engine but have heard that Juby app on
I have been considering using the code example shown at Shell Style Drag and
Considering I have an array of objects, and all objects represent something out of
Considering I have a continuous joint distribution of two independent normal random variables (let's
I have a histogram produced using plot in the ggplot2 package: and a table
I have been considering a range of options to move away form using scriptlets
Considering that I have a Schema named SBST I want to find all empty

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.