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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:07:10+00:00 2026-06-11T11:07:10+00:00

I have a 3d matrix grid_z0 , whose dimension are (let’s say) 50x25x36. Each

  • 0

I have a 3d matrix grid_z0, whose dimension are (let’s say) 50x25x36. Each point of this matrix represents a cell. I would like to convert this matrix into a 1D array of size 50x25x36. I would also like to create 3 array of the same size showing the coordinate of the cell center.
The array cx,cy and cz stores the coordinate of the cell center in one direction.

This example work but it rather slow, especially for large data set. Is there a way to make it faster?

data={"x":[],"y":[],"z":[],"rho":[]}

for i in arange(0,50):
  for j in arange(0,25):
    for k in arange(0,36):
      data["x"].append(cx[i])
      data["y"].append(cy[j])
      data["z"].append(cz[k])
      data["f"].append(grid_z0[i][j][k])
  • 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-11T11:07:11+00:00Added an answer on June 11, 2026 at 11:07 am

    You should consider using NumPy.

    >>> import numpy as np
    >>> a = np.random.rand(50,25,36) # Create a fake array
    >>> print a.shape
    (50, 25, 36)
    >>> a.shape = -1 # Flatten the array in place
    >>> print a.shape
    (45000,)
    

    When flattening your array, you’re doing the equivalent of :

    >>> b = []
    >>> for i in range(a.shape[0]):
    ...     for j in range(a.shape[1]):
    ...         for k in range(a.shape[2]):
    ...             b.append(a[i,j,k])
    

    That is, the last axis is parsed first, then the second, then the first.

    Given your three 1D lists cx, cy, cz of length N, you can construct a 2D array with:

    >>> centers = np.array([cx,cy,cz])
    >>> print centers.shape
    (3, N)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 2-dimensional integer array (say 1000 by 1000), let's call it matrix.
I have matrix (a) with (1:10),<10 x 1> double. I would like to copy
I have a matrix of objects that contains data in this form: name A,2,name
I have a matrix in the type of a Numpy array. How would I
I have matrix with 3 dimension (n*m*k). I am trying to fined the maximum
In Matlab I have this matrix: Grid with dimensions [x,y] I've reshaped it to
I have a 3 dimensional grid, in which for each point of the grid
I have defined an S4 class called cell , instances of which I would
I have a 3x3 matrix grid. If a user on particular cell, how can
I have a matrix in SQL reporting and I would like it to print

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.