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 6758169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:44:49+00:00 2026-05-26T13:44:49+00:00

i have this : npoints=10 vectorpoint=random.uniform(-1,1,[1,2]) experiment=random.uniform(-1,1,[npoints,2]) and now i want to create an

  • 0

i have this :

npoints=10

vectorpoint=random.uniform(-1,1,[1,2])
experiment=random.uniform(-1,1,[npoints,2])

and now i want to create an array with dimensions [1,npoints].
I can’t think how to do this.
For example table=[1,npoints]

Also, i want to evaluate this:

for i in range(1,npoints):
    if experiment[i,0]**2+experiment[i,1]**2 >1:
        table[i]=0
    else:
        table[i]=1

I am trying to evaluate the experiment[:,0]**2+experiment[:,1]**2 and if it is >1 then an element in table becomes 0 else becomes 1.

The table must give me sth like [1,1,1,1,0,1,0,1,1,0].
I can’t try it because i can’t create the array “table”.
Also,if there is a better way (with list comprehensions) to produce this..

Thanks!

  • 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-05-26T13:44:50+00:00Added an answer on May 26, 2026 at 1:44 pm

    Try:

    table = (experiment[:,0]**2 + experiment[:,1]**2 <= 1).astype(int)
    

    You can leave off the astype(int) call if you’re happy with an array of booleans rather than an array of integers. As Joe Kington points out, this can be simplified to:

    table = 1 - (experiment**2).sum(axis=1).astype(int)
    

    If you really need to create the table array up front, you could do:

    table = zeros(npoints, dtype=int)
    

    (assuming that you’ve already import zeros from numpy). Then your for loop should work as written.

    Aside: I suspect that you want range(npoints) rather than range(1, npoints) in your for statement.

    Edit: just noticed that I had the 1s and 0s backwards. Now fixed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this matrix experiment=2*rand(npoints,3)-1 . I want to plot in in 3D,so i
I have this code to create a candlestick chart in rebol. Now I'd like
I have this string 2012-06-27 16:17:06 and I want to convert it to GMT
Have have this line of code in my form when I create a new
I have an array X of 3D coords of N points (N*3) and want
Have this print output from print_r($theobject); SimpleXMLElement Object ( [@attributes] => Array ( [label]
I have this code in jQuery, that I want to reimplement with the prototype
Have this objects and table types: CREATE TYPE Person_typ AS OBJECT ( name CHAR(20),
i have a sprite in an array when calling it like this [c1 objectAtIndex:0];
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt

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.