Skip to content

BUG: Applying np.fix on scalar returns 0-D array #8993

Closed
@jakirkham

Description

@jakirkham

Appears that when NumPy's fix function is given a scalar, it returns a 0-D array as the result. However, the documentation clearly shows it returning a scalar when given a scalar. Either this is a bug or the documentation needs to be updated. IMHO having a scalar returned when giving a scalar seems desirable. Example code and conda environment details below.

Code sample:

In [1]: import numpy as np

In [2]: np.fix(3.14)
Out[2]: array(3.0)

In [3]: np.fix(3)
Out[3]: array(3.0)

In [4]: np.fix([2.1, 2.9, -2.1, -2.9])
Out[4]: array([ 2.,  2., -2., -2.])

Environment:

# environment.yml
name: test
channels: !!python/tuple
- !!python/unicode
  'conda-forge'
- !!python/unicode
  'defaults'
dependencies:
- conda-forge::appnope=0.1.0=py27_0
- conda-forge::backports.shutil_get_terminal_size=1.0.0=py27_1
- conda-forge::blas=1.1=openblas
- conda-forge::ca-certificates=2017.1.23=1
- conda-forge::certifi=2017.4.17=py27_0
- conda-forge::decorator=4.0.11=py27_0
- conda-forge::enum34=1.1.6=py27_1
- conda-forge::ipython=5.3.0=py27_0
- conda-forge::ipython_genutils=0.2.0=py27_0
- conda-forge::libgfortran=3.0.0=0
- conda-forge::ncurses=5.9=10
- conda-forge::numpy=1.12.1=py27_blas_openblas_200
- conda-forge::openblas=0.2.19=2
- conda-forge::openssl=1.0.2k=0
- conda-forge::pathlib2=2.2.1=py27_0
- conda-forge::pexpect=4.2.1=py27_0
- conda-forge::pickleshare=0.7.3=py27_0
- conda-forge::prompt_toolkit=1.0.14=py27_0
- conda-forge::ptyprocess=0.5.1=py27_0
- conda-forge::pygments=2.2.0=py27_0
- conda-forge::python=2.7.13=0
- conda-forge::readline=6.2=0
- conda-forge::scandir=1.5=py27_1
- conda-forge::setuptools=33.1.1=py27_0
- conda-forge::simplegeneric=0.8.1=py27_0
- conda-forge::six=1.10.0=py27_1
- conda-forge::sqlite=3.13.0=1
- conda-forge::tk=8.5.19=1
- conda-forge::traitlets=4.3.2=py27_0
- conda-forge::wcwidth=0.1.7=py27_0
- conda-forge::zlib=1.2.11=0

Note: Sorry if this is a duplicate issue. Searching the issue tracker for "fix" was not very effective.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions