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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:09:45+00:00 2026-06-03T16:09:45+00:00

I am trying to rewrite a matlab code in python27. There is a matlab

  • 0

I am trying to rewrite a matlab code in python27. There is a matlab line as follows:

vector_C = vector_A > vector_B;

If I try to write this in python using numpy it will be the same, but the result will be an array of booleans instead of binaries. I want the result to be in binaries. Is there a way to make it return binary or should I convert manually each time? Is there a quick way of converting it? I am new to python. 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-06-03T16:09:48+00:00Added an answer on June 3, 2026 at 4:09 pm

    Even though vector_C may have dtype=bool, you can still do operations such as the following:

    In [1]: vector_A = scipy.randn(4)
    
    In [2]: vector_B = scipy.zeros(4)
    
    In [3]: vector_A
    Out[3]: array([ 0.12515902, -0.53244222, -0.67717936, -0.74164708])
    
    In [4]: vector_B
    Out[4]: array([ 0.,  0.,  0.,  0.])
    
    In [5]: vector_C = vector_A > vector_B
    
    In [6]: vector_C
    Out[6]: array([ True, False, False, False], dtype=bool)
    
    In [7]: vector_C.sum()
    Out[7]: 1
    
    In [8]: vector_C.mean()
    Out[8]: 0.25
    
    In [9]: 3 - vector_C
    Out[9]: array([2, 3, 3, 3])
    

    So, in short, you probably don’t have to do anything extra.

    But if you must do a conversion, you may use astype:

    In [10]: vector_C.astype(int)
    Out[10]: array([1, 0, 0, 0])
    
    In [11]: vector_C.astype(float)
    Out[11]: array([ 1.,  0.,  0.,  0.])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to rewrite code I've written in matlab in C++ instead. I have
I am trying to rewrite this messy code, so that I only make one
I'm trying to rewrite this url: http://www.example.com/user.php?user=username into http://example.com/username I'm using this code in
I'm trying to write a short Matlab code to perform a certain mathematical function.
I'm trying to rewrite a url of this: http://www.foo.com/bar/baz to index.php?q=$1&d=baz Where bar is
I'm trying to rewrite some query strings I have in my URL like this
I am trying to rewrite this url: http://www.sample.com/product_guide&product_name=waht&product_type=dog-clipper to: http://www.sample.com/waht/dog-clipper I am using this
I'm trying to rewrite a fairly simple MATLAB script in Haskell. I'm looking for
I'm trying to rewrite some code to make use of SSE. However, for some
I'm trying to rewrite some Spring 1.2 code to Spring 3.0 one. Currently I'm

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.