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

  • SEARCH
  • Home
  • 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 8724949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:55:53+00:00 2026-06-13T07:55:53+00:00

I am trying to get a random element from an array’s single dimension in

  • 0

I am trying to get a random element from an array’s single dimension in Python. So in the case below, I would like to retrieve any one of the 5 floats.

ar = rand(1, 5)

ar = array([[ 0.29889882,  0.84955019,  0.52989055,  0.57220576,  0.16841406]])

I have been able to retrieve a float if there are 5 elements and only one dimension
(ar = rand(5, 1)),

using:

ar[randrange(0, p.size)]

but how do I get a value from an array from a single dimension?

  • 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-13T07:55:54+00:00Added an answer on June 13, 2026 at 7:55 am

    Assuming you are referring to numpy.array, you can use the following:

    >>> import numpy as np
    >>> np.array([[ 0.29889882, 0.84955019, 0.52989055, 0.57220576, 0.16841406]])
    array([[ 0.29889882,  0.84955019,  0.52989055,  0.57220576,  0.16841406]])
    >>> 
    >>> 
    >>> ar = np.array([[ 0.29889882, 0.84955019, 0.52989055, 0.57220576, 0.16841406]])
    >>> ar[:, random.randint(0,4)]
    array([ 0.29889882])
    >>> ar[:, random.randint(0,4)]
    array([ 0.52989055])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to pick a random element from an array -- is this possible
Am trying to get a random photo from each album from the data created
I am a Python beginner who is trying to get multiple random lines for
I'm trying to get 4 random results from a table that holds approx 7
Im trying to get random number between -5 and 5. Im using this code:
Trying to get a random string out of ListArray on the button pressed. Always
I've struggled with this all day, I am trying to get a random number
Hi im trying to get a uniform random number generator using a crypto algorithm
Hi I am trying to get this script to show random colours one after
I'm trying get the visible portion of UIImage from an UIImageView . UIImageView takes

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.