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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:40:44+00:00 2026-06-08T19:40:44+00:00

By binary matrix, I mean every element in the matrix is either 0 or

  • 0

By binary matrix, I mean every element in the matrix is either 0 or 1, and I use the Matrix class in numpy for this.

First of all, is there a specific type of matrix in numpy for it, or do we simply use a matrix that is populated with 0s and 1s?

Second, what is the quickest way for creating a square matrix full of 0s given its dimension with the Matrix class? Note: numpy.zeros((dim, dim)) is not what I want, as it creates a 2-D array with float 0.

Third, I want to get and set any given row of the matrix frequently. For get, I can think of using row = my_matrix.A[row_index].tolist(), which will return a list representation of the given row. For set, it seems that I can just do my_matrix[row_index] = row_list, with row_list being a list of the same length as the given row. Again, I wonder whether they are the most efficient methods for doing the jobs.

  • 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-08T19:40:47+00:00Added an answer on June 8, 2026 at 7:40 pm

    To make a numpy array whose elements can be either 0 or 1, use the dtype = 'bool' parameter:

    arr = np.zeros((dim,dim), dtype = 'bool')
    

    Or, to convert arr to a numpy matrix:

    arr = np.matrix(arr)
    

    To access a row:

    arr[row_num]
    

    and to set a row:

    arr[row_num] = new_row
    

    is the quickest way.

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

Sidebar

Related Questions

I have a Binary Search Tree, I use template to add any class object
Given a binary matrix in which every row and column contains exactly only one
There is a square binary matrix that denotes connections in a bipartite graph. The
I am trying to binary serialize the data of vector. In this sample below
I have a 2D binary matrix that I want to display as a black
Can the values in User-Item matrix be binary values like 0 and 1 which
I need to read a large (2000x2000) matrix of binary data from a file
I'm trying to read a binary file (which represents a matrix in Matlab) in
There is a php script which sends a binary string to the client application:
I would like to store and load numpy arrays from binary files. For that

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.