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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:07:32+00:00 2026-06-12T20:07:32+00:00

I have Array2D of 0 and 1: let rnd = System.Random() let a =

  • 0

I have Array2D of 0 and 1:

let rnd = System.Random()
let a = Array2D.init n n (fun i j  -> int(System.Math.Round(rnd.NextDouble() / index)) )

I need to calculate the count of ‘1’-elements, something like:

a |> Array.filter (fun x -> x == 1)

But ‘a’ is Array2D (not Array) so I’m just wondering if there is a standard way to transform Array2D to Array?

  • 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-12T20:07:33+00:00Added an answer on June 12, 2026 at 8:07 pm

    Here is one easy way, using the fact that [,] implements ienumerable<_>

    a |> Seq.cast<int> |> Seq.filter (fun x -> x == 1)
    

    but if you only need the count you can do

    a |> Seq.cast<int> |> Seq.sum
    

    as the 0 terms won’t add to the sum and the terms you want to count are just 1

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

Sidebar

Related Questions

I have a matrix: Array2D and a function let DivideAndSubstract value index (matrix: float[,])
Let's say I have two arrays: int[] array1 = new int[2000000]; int[] array2 =
I have a list of point and have to do erosion/dilation operations. I need
I have a structure typedef struct foo { int lengthOfArray1; int lengthOfArray2; int* array1;
I have the following two methods: public int Average (params int[] array) { if
I have two arrays: var array1 = [a,b,c,d]; var array2 = [1,2,a,b]; I need
Considering I have two arrays for example: String[] array1 = new String[10]; int[] array2=
I have two nsmutablearrays array1: searchedStores = [[NSMutableArray alloc] init]; array2: allStores; ///it holds
Let's say I have these two arrays: var array1 = new[] {"A", "B", "C"};
let's say i have 2 array. array1: value = 2 value = 1 value

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.