• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python shape_base.apply_along_axis函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.lib.shape_base.apply_along_axis函数的典型用法代码示例。如果您正苦于以下问题:Python apply_along_axis函数的具体用法?Python apply_along_axis怎么用?Python apply_along_axis使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了apply_along_axis函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_0d_array

    def test_0d_array(self, cls=np.ndarray):
        def sum_to_0d(x):
            """ Sum x, returning a 0d array of the same class """
            assert_equal(x.ndim, 1)
            return np.squeeze(np.sum(x, keepdims=True))
        a = np.ones((6, 3)).view(cls)
        res = apply_along_axis(sum_to_0d, 0, a)
        assert_(isinstance(res, cls))
        assert_array_equal(res, np.array([6, 6, 6]).view(cls))

        res = apply_along_axis(sum_to_0d, 1, a)
        assert_(isinstance(res, cls))
        assert_array_equal(res, np.array([3, 3, 3, 3, 3, 3]).view(cls))
开发者ID:Jengel1,项目名称:SunriseSunsetTimeFinder,代码行数:13,代码来源:test_shape_base.py


示例2: test_preserve_subclass

    def test_preserve_subclass(self):
        # this test is particularly malicious because matrix
        # refuses to become 1d
        def double(row):
            return row * 2
        m = np.matrix([[0, 1], [2, 3]])
        expected = np.matrix([[0, 2], [4, 6]])

        result = apply_along_axis(double, 0, m)
        assert_(isinstance(result, np.matrix))
        assert_array_equal(result, expected)

        result = apply_along_axis(double, 1, m)
        assert_(isinstance(result, np.matrix))
        assert_array_equal(result, expected)
开发者ID:jonovik,项目名称:numpy,代码行数:15,代码来源:test_shape_base.py


示例3: test_scalar_array

 def test_scalar_array(self):
     class MinimalSubclass(np.ndarray):
         pass
     a = np.ones((6, 3)).view(MinimalSubclass)
     res = apply_along_axis(np.sum, 0, a)
     assert isinstance(res, MinimalSubclass)
     assert_array_equal(res, np.array([6, 6, 6]).view(MinimalSubclass))
开发者ID:ContinuumIO,项目名称:numpy,代码行数:7,代码来源:test_shape_base.py


示例4: transform

    def transform(self, x, use_spln=False, **kwargs):
        """
        Apply transform to x

        Parameters
        ----------
        x : float-array-convertible
            Data to be transformed.
            Should support conversion to an array of floats.
        use_spln: bool
            True - transform using the spline specified in self.slpn.
                    If self.spln is None, set the spline.
            False - transform using self.tfun
        kwargs:
            Keyword arguments to be passed to self.set_spline.
            Only used if use_spln=True & self.spln=None.

        Returns
        -------
        Array of transformed values.
        """
        x = asarray(x, dtype=float)

        if use_spln:
            if self.spln is None:
                self.set_spline(x.min(), x.max(), **kwargs)
            return apply_along_axis(self.spln, 0, x)
        else:
            return self.tfun(x, *self.args, **self.kwargs)
开发者ID:eyurtsev,项目名称:FlowCytometryTools,代码行数:29,代码来源:transforms.py


示例5: test_preserve_subclass

    def test_preserve_subclass(self):
        def double(row):
            return row * 2

        class MyNDArray(np.ndarray):
            pass

        m = np.array([[0, 1], [2, 3]]).view(MyNDArray)
        expected = np.array([[0, 2], [4, 6]]).view(MyNDArray)

        result = apply_along_axis(double, 0, m)
        assert_(isinstance(result, MyNDArray))
        assert_array_equal(result, expected)

        result = apply_along_axis(double, 1, m)
        assert_(isinstance(result, MyNDArray))
        assert_array_equal(result, expected)
开发者ID:Jengel1,项目名称:SunriseSunsetTimeFinder,代码行数:17,代码来源:test_shape_base.py


示例6: test_preserve_subclass

 def test_preserve_subclass(self):
     def double(row):
         return row * 2
     m = np.matrix([[0, 1], [2, 3]])
     result = apply_along_axis(double, 0, m)
     assert isinstance(result, np.matrix)
     assert_array_equal(
         result, np.matrix([[0, 2], [4, 6]])
     )
开发者ID:ContinuumIO,项目名称:numpy,代码行数:9,代码来源:test_shape_base.py


示例7: test_subclass

    def test_subclass(self):
        class MinimalSubclass(np.ndarray):
            data = 1

        def minimal_function(array):
            return array.data

        a = np.zeros((6, 3)).view(MinimalSubclass)

        assert_array_equal(
            apply_along_axis(minimal_function, 0, a), np.array([1, 1, 1])
        )
开发者ID:ContinuumIO,项目名称:numpy,代码行数:12,代码来源:test_shape_base.py


示例8: test_axis_insertion_ma

 def test_axis_insertion_ma(self):
     def f1to2(x):
         """produces an asymmetric non-square matrix from x"""
         assert_equal(x.ndim, 1)
         res = x[::-1] * x[1:,None]
         return np.ma.masked_where(res%5==0, res)
     a = np.arange(6*3).reshape((6, 3))
     res = apply_along_axis(f1to2, 0, a)
     assert_(isinstance(res, np.ma.masked_array))
     assert_equal(res.ndim, 3)
     assert_array_equal(res[:,:,0].mask, f1to2(a[:,0]).mask)
     assert_array_equal(res[:,:,1].mask, f1to2(a[:,1]).mask)
     assert_array_equal(res[:,:,2].mask, f1to2(a[:,2]).mask)
开发者ID:Jengel1,项目名称:SunriseSunsetTimeFinder,代码行数:13,代码来源:test_shape_base.py


示例9: test_axis_insertion

    def test_axis_insertion(self, cls=np.ndarray):
        def f1to2(x):
            """produces an asymmetric non-square matrix from x"""
            assert_equal(x.ndim, 1)
            return (x[::-1] * x[1:,None]).view(cls)

        a2d = np.arange(6*3).reshape((6, 3))

        # 2d insertion along first axis
        actual = apply_along_axis(f1to2, 0, a2d)
        expected = np.stack([
            f1to2(a2d[:,i]) for i in range(a2d.shape[1])
        ], axis=-1).view(cls)
        assert_equal(type(actual), type(expected))
        assert_equal(actual, expected)

        # 2d insertion along last axis
        actual = apply_along_axis(f1to2, 1, a2d)
        expected = np.stack([
            f1to2(a2d[i,:]) for i in range(a2d.shape[0])
        ], axis=0).view(cls)
        assert_equal(type(actual), type(expected))
        assert_equal(actual, expected)

        # 3d insertion along middle axis
        a3d = np.arange(6*5*3).reshape((6, 5, 3))

        actual = apply_along_axis(f1to2, 1, a3d)
        expected = np.stack([
            np.stack([
                f1to2(a3d[i,:,j]) for i in range(a3d.shape[0])
            ], axis=0)
            for j in range(a3d.shape[2])
        ], axis=-1).view(cls)
        assert_equal(type(actual), type(expected))
        assert_equal(actual, expected)
开发者ID:Jengel1,项目名称:SunriseSunsetTimeFinder,代码行数:36,代码来源:test_shape_base.py


示例10: test_3d

 def test_3d(self):
     a = np.arange(27).reshape((3, 3, 3))
     assert_array_equal(apply_along_axis(np.sum, 0, a),
                        [[27, 30, 33], [36, 39, 42], [45, 48, 51]])
开发者ID:ContinuumIO,项目名称:numpy,代码行数:4,代码来源:test_shape_base.py


示例11: test_simple101

 def test_simple101(self, level=11):
     a = np.ones((10, 101), 'd')
     assert_array_equal(
         apply_along_axis(len, 0, a), len(a)*np.ones(a.shape[1]))
开发者ID:ContinuumIO,项目名称:numpy,代码行数:4,代码来源:test_shape_base.py


示例12: test_simple

 def test_simple(self):
     a = np.ones((20, 10), 'd')
     assert_array_equal(
         apply_along_axis(len, 0, a), len(a)*np.ones(a.shape[1]))
开发者ID:ContinuumIO,项目名称:numpy,代码行数:4,代码来源:test_shape_base.py


示例13: test_scalar_array

 def test_scalar_array(self, cls=np.ndarray):
     a = np.ones((6, 3)).view(cls)
     res = apply_along_axis(np.sum, 0, a)
     assert_(isinstance(res, cls))
     assert_array_equal(res, np.array([6, 6, 6]).view(cls))
开发者ID:Jengel1,项目名称:SunriseSunsetTimeFinder,代码行数:5,代码来源:test_shape_base.py



注:本文中的numpy.lib.shape_base.apply_along_axis函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python shape_base.array_split函数代码示例发布时间:2022-05-27
下一篇:
Python scimath.sqrt函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap