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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:44:59+00:00 2026-06-18T18:44:59+00:00

I have a list of numbers which I put into a numpy array: >>>

  • 0

I have a list of numbers which I put into a numpy array:

>>> import numpy as np
>>> v=np.array([10.0, 11.0])

then I want to subtract a number from each value in the array. It can be done like this with numpy arrays:

>>> print v - 1.0
[  9.  10.]

Unfortunately, my data often contains missing values, represented by None. For this kind of data I get this error:

>>> v=np.array([10.0, 11.0, None])
>>> print v - 1.0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'

What I would like to get for the above example is:

 [  9.  10.  None]

How can I achieve it in an easy and efficient way?

  • 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-18T18:45:00+00:00Added an answer on June 18, 2026 at 6:45 pm

    My recommendation is to either use masked arrays:

    v = np.ma.array([10., 11, 0],mask=[0, 0, 1])
    print v - 10
    >>> [0.0 1.0 --]
    

    or NaNs

    v = np.array([10.,11,np.nan])
    print v - 10
    >>> [  0.   1.  nan]
    

    I actually prefer NaNs as missing data indicators.

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

Sidebar

Related Questions

I have a list of numbers and need to put them all into a
I have a list of Phone Numbers which I need to convert into a
I have a list of numbers which looks like this: 1.234D+1 or 1.234D-02 .
I have a list of numbers, for example: list=[10,50,90,60] I want to sorte the
I have a list of numbers ( integers ) (say, from 1 to 10).
If I have a list of numbers like this one: 10,9,8,8,9,7,6,5,4,6,7,8,11,10,12,14,16,20,30,29,28,29,27,25,20,18,15,10,8,5,4,1 I want to
If i have a list of numbers: 1,2,3,4,5,6,7,8 and I want to order by
I have a long list of strings which need converting to numbers according to
I have a string which has a version number. I want to read the
From MySQL query I get data which I put into a dictionary d: d

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.