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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:55:55+00:00 2026-06-18T23:55:55+00:00

I have thoroughly looked around to try figuring out a way to create a

  • 0

I have thoroughly looked around to try figuring out a way to create a matlab like struct array in python. There are some questions online that I looked at and either the answers don’t seem to help or I might simply be misinterpreting them as they pertain to me. So, moving on. I am trying to form a python equivalent to the following matlab code.

channel                 = [];
channel.PRN             = 0; 
channel.acquiredFreq    = 0; 
channel.codePhase       = 0; 
channel.status          = '-';  
channel = repmat(channel, 1, settings.numberOfChannels); 

Where repmat would basically create a struct array called channel with a number of cells equal to settings.numberOfChannels and each of those would have PRN,acquiredFreq, etc.

Later on, I access this struct by performing a loop that alters these values as such:

for ii = 1:settings.numberOfChannels
        channel(ii).PRN          = PRNindexes(ii);
        channel(ii).acquiredFreq = acqResults.carrFreq(PRNindexes(ii));
        channel(ii).codePhase    = acqResults.codePhase(PRNindexes(ii));

I have tried several approaches but it either spits out nonsense in the case of tile using numpy(which i might have just been using incorrectly) or when I attempt to make a loop such as:

class test:
    for iii in range(1,settings.numberOfChannels):
        iii.PRN=0
        iii.acquiredFreq=0
        iii.codePhase=0
        iii.status="-"

More than likely I suppose it’s a syntax error or my misunderstanding of python since this is my first time utilizing it. If this is the incorrect place to ask this or something of that nature, I apologize.

Thank you

  • 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-18T23:55:56+00:00Added an answer on June 18, 2026 at 11:55 pm

    Update: You may want to investigate Pandas. Its
    Series and DataFrames are easier to work with and more full-featured than NumPy
    structured arrays.


    You could use a NumPy structured array:

    import numpy as np
    channel = np.zeros(1, dtype = [('PRN',int),
                                   ('acquiredFreq',int),
                                   ('codePhase',int),
                                   ('status','|S1')])
    
    print(channel)
    # [(0, 0, 0, '')]
    

    Indexing by integer accesses a particular row:

    print(channel[0])
    # (0, 0, 0, '')
    

    Indexing by column name returns the column as an array:

    print(channel['PRN'])
    # [0]
    

    Or you can loop through each row and assign to each field (column),
    but this is relatively slow in NumPy.

    for row in channel:
        row['PRN'] = 1
        row['acquiredFreq'] = 1
        row['codePhase'] = 1
        row['status'] = '+'
    
    print(channel)    
    # [(1, 1, 1, '+')]
    

    Just for completeness, I’ll also mention you can assign by row then column:

    channel[0]['status'] = '-'
    print(channel)
    # [(1, 1, 1, '-')]
    

    or assign by column then row:

    channel['PRN'][0] = 10
    print(channel)
    # [(10, 1, 1, '-')]
    

    I showed the above because it is most similar to the Matlab code you posted. However, let me stress again that assigning to individual cells in a NumPy array is slow. The NumPy-way to do the above is to do whole-array assignments instead:

    channel['PRN'] = PRNindexes
    

    where PRNindexes is a sequence (e.g. a list, tuple, or NumPy array).


    You can also use fancy indexing (aka “advanced indexing”) to select rows:

    index = (channel.status == '+')  # Select all rows with status '+'
    channel['PRN'][index] = 10       # Set PRN to 10 for all those rows
    

    Just keep in mind that fancy indexing returns a new array, not a view of the original array. (In contrast, “basic slicing” (e.g. channel[0] or channel[1:10] returns a view.) So if you want to make assignments that alter the original array, select by column first, then fancy index (index)

    channel['PRN'][index] = ...
    

    rather than

    channel[index]['PRN'] = ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked thoroughly, but I have not found the solution (or perhaps I
Ok, so I have an array like so: 1 2 3 4 5 6
I have thoroughly looked through this forum and I have not found a solution
I'm thoroughly puzzled. I have a block of HTML that I scraped out of
I'm thoroughly puzzled. I have a block of HTML that I scraped out of
I've thoroughly looked for a solution and have not found one. It seems really
I realize this is an unbelievably common issue and have looked very very thoroughly
I have been trying like hell to figure out how to establish a connection
I have an .ocx/ActiveX library that I coded in Delphi. I have thoroughly tested
I have an app which was tested thoroughly and working fine on Android Gingerbread

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.