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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:30:03+00:00 2026-06-12T17:30:03+00:00

I have an array defined as – import numpy as np A = np.recarray((3,),dtype=[(‘x’,float),

  • 0

I have an array defined as –

import numpy as np
A = np.recarray((3,),dtype=[('x',float), ('y', float), ('z',float)])

Plus another array B which is read from a CSV file as –

>>> print B
[(7.0, 0.0, 7.0) (16.0, 0.0, 1.0)]

When I try to add the elements to array as given below –

for i in range(B.size):
    if(B[i][0] != 0.):
        A.append((0.,B[i][1],B[i][2]))
    if(B[i][1] != 0.):
        A.append((B[i][0],0.,B[i][2]))
    if(B[i][2] != 0.):
        A.append((B[i][0],B[i][1],0.))

I get an error as follows –

File "/usr/lib/python2.7/dist-packages/numpy/core/records.py", line 416, in __getattribute__
    raise AttributeError, "record array has no attribute %s" % attr
    AttributeError: record array has no attribute append

I am not able to understand where does this string attribute (%s) is coming into picture?

Can someone help out please?

UPDATE:
I changed the code to np.append(A,(0.,B[i][1],B[i][2])), however I get another error as – TypeError: invalid type promotion

  • 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-12T17:30:05+00:00Added an answer on June 12, 2026 at 5:30 pm

    Appending to a numpy array is a slow operation because new memory has to be allocated and the entire array has to be copied. Doing this for each row of B would be inefficient. Avoid this if you can.

    If you know the shape of A and minors(B) (see below) in advance, it is best to make an array which is big enough to accomodate both from the beginning.

    There are many was to do what you asking. @seberg’s np.lib.recfunctions.stack_arrays idea would make a viable solution as long as the dtypes of A and B are the same.

    Here is another possibility, which will work even if B has a different dtype, or is just a ndarray or list of lists.

    import itertools
    import numpy as np
    
    def minors(arr):
        for row in arr:
            row = list(row)
            for i, elt in enumerate(row):
                if elt != 0:
                    for val in row[:i]+[0]+row[i+1:]:
                        yield val
    
    A = np.recarray((3,),dtype=[('x',float), ('y', float), ('z',float)])
    B = [(7.0, 0.0, 7.0), (16.0, 0.0, 1.0)]
    
    C = np.fromiter(itertools.chain(A.view(float), minors(B)), dtype = float)
    C = C.view(A.dtype)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java array defined already e.g. float[] values = new float[3]; I
I have a program, which takes a parameter from the args[] array, defined in
I have an array defined in a file and in another I have to
Assume I have an array which holds some struct defined as follows: static struct
I have defined an array: float array[3][4][5]; then, what is the difference when array,
An array is defined of assumed elements like I have array like String[] strArray
I have an array defined as; static double Temp_data[TABLE_SIZE]; I want to change the
I have defined an array like so : var myArray = {myNewArray: ['string1' ,
Background I have an array of objects (Users) defined and set as follows: //
I have been trying to assign value to an object array that is defined

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.